Created
March 16, 2018 05:28
-
-
Save elialejandro/c4af1a88d1f47f8dded2511a136a1ce4 to your computer and use it in GitHub Desktop.
Add student
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include 'connect.php'; | |
if (isset($_POST['add'])) { | |
$studentId = $_POST['studentId']; | |
$firstname = $_POST['firstname']; | |
$middlename = $_POST['middlename']; | |
$lastname = $_POST['lastname']; | |
$contactnumber = $_POST['contactnumber']; | |
$email = $_POST['email']; | |
$student_status = $_POST['studente_status']; | |
$departament = $_POST['departament']; | |
$year_level = $_POST['year_level']; | |
$course = $_POST['course']; | |
// I suppose that you are use pdo_mysql and student_id is not AUTO_INCREMENT | |
$statement = $conn->prepare('INSERT INTO add_student (student_id, student_Fname, student_Mname, student_Lname, Contact_num, Email, student_status, Department, Year_level, course_progress) | |
VALUES (?,?,?,?,?,?,?,?,?,?)'); | |
$statement->execute(array($studentId, $firstname, $middlename, $lastname, $contactnumber, $email, $student_status, $departament, $year_level, $course)); | |
/** | |
* If student_id is AUTO_INCREMENT | |
* | |
* $statement = $conn->prepare('INSERT INTO add_student (student_Fname, student_Mname, student_Lname, Contact_num, Email, student_status, Department, Year_level, course_progress) | |
* VALUES (?,?,?,?,?,?,?,?,?)'); | |
* $statement->execute(array($studentId, $firstname, $middlename, $lastname, $contactnumber, $email, $student_status, $departament, $year_level, $course)); | |
* | |
* $studentId = $conn->lastInsertId(); | |
*/ | |
// Check existence | |
$statement = $conn->prepare('SELECT * FROM add_student WHERE student_id = :studentId'); | |
$statement->execute(array('studentId' => $studentId)); | |
$row = $statement->fetch(PDO::FETCH_OBJ); | |
if (!empty($row)) { | |
echo "Student created"; | |
} else { | |
echo "Error, student not created"; | |
} | |
$statement = $conn->prepare('INSERT INTO clearance (id) VALUES (?)'); | |
$statement->execute(array($studentId)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment