0

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)

  1. First name = $first_name
  2. Last name = $last_name
  3. gender = $gender
  4. username = $applicantusername
  5. password = $pwd
  6. Email = $email

tblEducational (educ_id, userId, school, school_type)

  1. School description = $school

  2. 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();
 }
Pablo
  • 1,357
  • 1
  • 11
  • 40

0 Answers0