Untitled
unknown
plain_text
a year ago
14 kB
1
Indexable
Never
<?php require 'connect_to_database.php'; $student_number = $student_number_err = ""; $user_password = $user_password_err = ""; $confirm_password = $confirm_password_err = ""; $course_level = $course_level_err = ""; $year_level = $year_level_err = ""; $last_name = $last_name_err = ""; $first_name = $first_name_err = ""; $middle_name = $middle_name_err = ""; $gender = $gender_err = ""; $birth_day = $birth_day_err = ""; $religion = $religion_err = ""; $contact_number = $contact_number_err = ""; $email = $email_err = ""; $unit_number = $unit_number_err = ""; $street = $street_err = ""; $barangay = $barangay_err = ""; $city = $city_err = ""; $zip_code = $zip_code_err = ""; $sql = "Select * FROM tblcourse_level"; $result = mysqli_query($conn, $sql); $options2 = "<option>Select a Course Level</option>"; while ($row = mysqli_fetch_array($result)) { $options2 = $options2 . "<option value='$row[0]'>$row[1]</option>"; } $sql = "Select * FROM tblyear_level"; $result = mysqli_query($conn, $sql); $options3 = "<option>Select a Year Level</option>"; while ($row = mysqli_fetch_array($result)) { $options3 = $options3 . "<option value='$row[0]'>$row[1]</option>"; } if($_SERVER["REQUEST_METHOD"] == "POST") { $input_student_number = trim($_POST["student_number"]); if(empty($input_student_number)){ $student_number_err = "Please enter a student number."; } else{ $student_number = (int)$input_student_number; } $input_user_password = trim($_POST["user_password"]); if(empty($input_user_password)){ $user_password_err = "Please enter a user password."; } else{ $user_password = $input_user_password; } $input_confirm_password = trim($_POST["confirm_password"]); if(empty($input_confirm_password)){ $confirm_password_err = "Please enter a confirm password."; } else{ $confirm_password = $input_confirm_password; } if ($user_password != $confirm_password){ $user_password_err = "User password and confirm password are not the same."; $confirm_password_err = "User password and confirm password are not the same."; } $input_course_level = trim($_POST["course_level"]); if($input_course_level == "Select a Course Level") { $course_level_err = "Please Select a course level."; } else{ $course_level = (int)$input_course_level; } $input_year_level = trim($_POST["year_level"]); if($input_year_level == "Select a Year Level") { $year_level_err = "Please Select a year level."; } else{ $year_level = (int)$input_year_level; } $input_last_name = trim($_POST["last_name"]); if(empty($input_last_name)){ $last_name_err = "Please enter a last name."; } else{ $last_name = $input_last_name; } $input_first_name = trim($_POST["first_name"]); if(empty($input_first_name)){ $first_name_err = "Please enter a first name."; } else{ $first_name = $input_first_name; } $input_middle_name = trim($_POST["middle_name"]); if(empty($input_middle_name)){ $middle_name_err = "Please enter a middle name."; } else{ $middle_name = $input_middle_name; } $input_gender = trim($_POST["gender"]); if(empty($input_gender)){ $gender_err = "Please enter a gender."; } else{ $gender = $input_gender; } $birth_day = trim($_POST["birth_day"]); if(empty($birth_day)){ $birth_day_err = "Please enter a date of birth."; } else{ $birth_day = $birth_day; } $input_religion = trim($_POST["religion"]); if(empty($input_religion)){ $religion_err = "Please enter a religion."; } else{ $religion = $input_religion; } $input_contact_number = trim($_POST["contact_number"]); if(empty($input_contact_number)){ $contact_number_err = "Please enter a contact number."; } else{ $contact_number = (int)$input_contact_number; } $input_email = trim($_POST["email"]); if(empty($input_email)){ $email_err = "Please enter a email."; } else{ $email = $input_email; } $input_unit_number = trim($_POST["unit_number"]); if(empty($input_unit_number)){ $unit_number_err = "Please enter a unit number."; } else{ $unit_number = $input_unit_number; } $input_street = trim($_POST["street"]); if(empty($input_street)){ $street_err = "Please enter a street."; } else{ $street = $input_street; } $input_barangay = trim($_POST["barangay"]); if(empty($input_barangay)){ $barangay_err = "Please enter a barangay."; } else{ $barangay = $input_barangay; } $input_city = trim($_POST["city"]); if(empty($input_city)){ $city_err = "Please enter a city."; } else{ $city = $input_city; } $input_zip_code = trim($_POST["zip_code"]); if(empty($input_zip_code)){ $zip_code_err = "Please enter a zip code."; } else{ $zip_code = (int)$input_zip_code; } if (empty($student_number_err) and empty($user_password_err) and empty($confirm_password_err) and empty($course_level_err) and empty($year_level_err) and empty($last_name_err) and empty($first_name_err) and empty($middle_name_err) and empty($gender_err) and empty($birth_day_err) and empty($religion_err) and empty($contact_number_err) and empty($email_err) and empty($unit_number_err) and empty($street_err) and empty($barangay_err) and empty($city_err) and empty($zip_code_err)){ $sql = "INSERT INTO tbl_user (student_number, user_password, course_level, year_level, last_name, first_name, middle_name, gender, birth_day, religion, contact_number, email, unit_number, street, barangay, city, zip_code) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; if ($stmt = mysqli_prepare($conn, $sql)){ mysqli_stmt_bind_param($stmt, "sssssssssssssssss", $param_student_number, $param_user_password, $param_course_level, $param_year_level, $param_last_name, $param_first_name, $param_middle_name, $param_gender, $param_birth_day, $param_religion, $param_contact_number, $param_email, $param_unit_number, $param_street, $param_barangay, $param_city, $param_zip_code); $param_student_number = $student_number; $param_user_password = md5($user_password); $param_course_level = $course_level; $param_year_level = $year_level; $param_last_name = $last_name; $param_first_name = $first_name; $param_middle_name = $middle_name; $param_gender = $gender; $param_birth_day = $birth_day; $param_religion = $religion; $param_contact_number = $contact_number; $param_email = $email; $param_unit_number = $unit_number; $param_street = $street; $param_barangay = $barangay; $param_city = $city; $param_zip_code = $zip_code; if(mysqli_stmt_execute($stmt)){ header("location: list_of_students.php"); exit(); } else{ ##diri ang mo error if naa nay same ID ang nag register OR number echo "Oops!<br>Something went wrong.<br>Please try again laterss."; } mysqli_close($conn); } } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>New User Account</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> <style> .wrapper{ width: 600px; margin: 0 auto; } </style> </head> <body> <div class="wrapper"> <div class="container-fluid"> <div class="row"> <div class="col-md-12"> <h2 class="mt-5">Add New User Account</h2> <p>Please fill this form and click Save User Account button to add new user account to the database</p> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post"> <div class="form-group"> <label>Student ID:</label> <input type="number" name="student_number" class="form-control <?php echo (!empty($student_number_err)) ?'is-invalid' : ''; ?>" value="<?php echo $student_number; ?>"></input> <span class="invalid-feedback"><?php echo $student_number_err;?></span> </div> <div class="form-group"> <label>User Password:</label> <input type="password" name="user_password" class="form-control <?php echo (!empty($user_password_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $user_password; ?>"></input> <span class="invalid-feedback"><?php echo $user_password_err;?></span> </div> <div class="form-group"> <label>Confirm Password:</label> <input type="password" name="confirm_password" class="form-control <?php echo (!empty($confirm_password_err)) ? 'is-invalid' : ''; ?>" value="<?php echo $confirm_password; ?>"></input> <span class="invalid-feedback"><?php echo $confirm_password_err;?></span> </div> <div class="form-group"> <label>Course:</label> <select name="course_level" class="form-control <?php echo (!empty($course_level_err)) ? 'is-invalid': ''; ?>"> <?php echo $options2; ?> </select> <span class="invalid-feedback"><?php echo $course_level_err;?></span> </div> <div class="form-group"> <label>Year Level:</label> <select name="year_level" class="form-control <?php echo (!empty($year_level_err)) ? 'is-invalid': ''; ?>"> <?php echo $options3; ?> </select> <span class="invalid-feedback"><?php echo $year_level_err;?></span> </div> <div class="form-group"> <label>Last Name:</label> <input type="text" name="last_name" class="form-control <?php echo (!empty($last_name_err)) ?'is-invalid' : ''; ?>" value="<?php echo $last_name; ?>"></input> <span class="invalid-feedback"><?php echo $last_name_err;?></span> </div> <div class="form-group"> <label>First Name:</label> <input type="text" name="first_name" class="form-control <?php echo (!empty($first_name_err)) ?'is-invalid' : ''; ?>" value="<?php echo $first_name; ?>"></input> <span class="invalid-feedback"><?php echo $first_name_err;?></span> </div> <div class="form-group"> <label>Middle Name:</label> <input type="text" name="middle_name" class="form-control <?php echo (!empty($middle_name_err)) ?'is-invalid' : ''; ?>" value="<?php echo $middle_name; ?>"></input> <span class="invalid-feedback"><?php echo $middle_name_err;?></span> </div> <div class="form-group"> <label>Gender:</label> <input type="text" name="gender" class="form-control <?php echo (!empty($gender_err)) ?'is-invalid' : ''; ?>" value="<?php echo $gender; ?>"></input> <span class="invalid-feedback"><?php echo $gender_err;?></span> </div> <div class="form-group"> <label>Date of Birth:</label> <input type="date" name="birth_day" class="form-control <?php echo (!empty($birth_day_err)) ?'is-invalid' : ''; ?>" value="<?php echo $birth_day; ?>"></input> <span class="invalid-feedback"><?php echo $birth_day_err;?></span> </div> <div class="form-group"> <label>Religion:</label> <input type="text" name="religion" class="form-control <?php echo (!empty($religion_err)) ?'is-invalid' : ''; ?>" value="<?php echo $religion; ?>"></input> <span class="invalid-feedback"><?php echo $religion_err;?></span> </div> <div class="form-group"> <label>Contact Number:</label> <input type="number" name="contact_number" class="form-control <?php echo (!empty($contact_number_err)) ?'is-invalid' : ''; ?>" value="<?php echo $contact_number; ?>"></input> <span class="invalid-feedback"><?php echo $contact_number_err;?></span> </div> <div class="form-group"> <label>Email:</label> <input type="text" name="email" class="form-control <?php echo (!empty($email_err)) ?'is-invalid' : ''; ?>" value="<?php echo $email; ?>"></input> <span class="invalid-feedback"><?php echo $email_err;?></span> </div> <div class="form-group"> <label>Unit Number:</label> <input type="text" name="unit_number" class="form-control <?php echo (!empty($unit_number_err)) ?'is-invalid' : ''; ?>" value="<?php echo $unit_number; ?>"></input> <span class="invalid-feedback"><?php echo $unit_number_err;?></span> </div> <div class="form-group"> <label>Street:</label> <input type="text" name="street" class="form-control <?php echo (!empty($street_err)) ?'is-invalid' : ''; ?>" value="<?php echo $street; ?>"></input> <span class="invalid-feedback"><?php echo $street_err;?></span> </div> <div class="form-group"> <label>Barangay:</label> <input type="text" name="barangay" class="form-control <?php echo (!empty($barangay_err)) ?'is-invalid' : ''; ?>" value="<?php echo $barangay; ?>"></input> <span class="invalid-feedback"><?php echo $barangay_err;?></span> </div> <div class="form-group"> <label>City:</label> <input type="text" name="city" class="form-control <?php echo (!empty($city_err)) ?'is-invalid' : ''; ?>" value="<?php echo $city; ?>"></input> <span class="invalid-feedback"><?php echo $city_err;?></span> </div> <div class="form-group"> <label>Zipcode:</label> <input type="number" name="zip_code" class="form-control <?php echo (!empty($zip_code_err)) ?'is-invalid' : ''; ?>" value="<?php echo $zip_code; ?>"></input> <span class="invalid-feedback"><?php echo $zip_code_err;?></span> </div> <input type="submit" class="btn btn-primary" value="Save User Account" href="list_of_students.php"></input> <a href="list_of_students.php" class="btn btn-danger">Cancel</a> </form> </div> </div> </div> </div> </body> </html>