I have a registration part where the form collects the personal and educational information of the user. This will be saved into 2 different tables.
tblPersonal (userId, first_name, last_name, gender, username, password, email)
- First name = $first_name
- Last name = $last_name
- gender = $gender
- username = $applicantusername
- password = $pwd
- Email = $email
tblEducational (educ_id, userId, school, school_type)
School description = $school
Type = $schooltype
The userId located from tblEducational is a foreign key coming from tblPersonal.
When the user fills up the form. The data will automatically save to these 2 different table. This should be done on a single submission.
The userId is AUTO_INCREMENT and will be created only when the data is inserted to the tblPersonal.
Problem:
(userId will be used to classify who's the person studied of a specific school)
How can I get the userId
When the data of tblPersonal and tblEducational should be inserted at the same time?
include("../../private/pdo-conn.php");
try
{
$connect = new PDO("mysql:host=$host;dbname=$database", $username, $password);
$connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = "INSERT INTO tblPersonal VALUES('','$first_name','$last_name','$gender','$applicantusername','$pwd','$email')";
$data = $connect->query($query);
//Query for inserting data into tblEducational??
//INSERT INTO tblEducational VALUES('',??,'$school','$schooltype'); My Idea, different query.
header("location: registration.php?success=true");
}
catch(PDOException $error)
{
$error->getMessage();
}