<?php
$FirstName = $_POST['FirstName'];
$MiddleName = $_POST['MiddleName'];
$LastName = $_POST['LastName'];
$Age = $_POST['Age'];
$HomeAddress = $_POST['HomeAddress'];
$ContactNumber = $_POST['ContactNumber'];
$LastSchoolAttended = $_POST ['LastSchoolAttended'];
$Strand = $_POST ['Strand'];
$SchoolAddress = $_POST ['SchoolAddress'];
$Adviser = $_POST ['Adviser'];
$Honor1 = $_POST ['Honor1'];
$Honor2 = $_POST ['Honor2'];
$Honor3 = $_POST ['Honor3'];
$Honor4 = $_POST ['Honor4'];
$Father = $_POST ['Father'];
$EducationalFather = $_POST ['EducationalFather'];
$Mother = $_POST ['Mother'];
$EducationalMother = $_POST ['EducationalMother'];
$Guardian = $_POST ['Guardian'];
$Occupation = $_POST ['Occupation'];
if (!empty($FirstName) || !empty($MiddleName) || !empty($LastName) || !empty($Age) || !empty($HomeAddress) || !empty($ContactNumber) || !empty($LastSchoolAttended) || !empty($Strand) || !empty($SchoolAddress) || !empty($Adviser) || !empty($Honor1) || !empty($Honor2)|| !empty($Honor3)|| !empty($Honor4) || !empty($Father) || !empty($EducationalFather) || !empty($Mother) || !empty($EducationalMother) || !empty($Guardian) || !empty($Occupation))
{
$host = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbname = "studentsinformation";
}
$conn = new mysqli($host, $dbUsername, $dbPassword, $dbname);
if (mysqli_connect_error())
{
die('Connect Error('.mysqli_connect_errno().')'.mysqli_connect_error());
}
else
{
$sql = "SELECT FirstName, MiddleName, LastName, LastSchoolAttended From personal Where FirstName = ? And MiddleName = ? And LastName = ? And LastSchoolAttended = ? Limit 1";
$sqlhonor = "SELECT Honor1, Honor2, Honor3, Honor4 From honor Where Honor1 = ? And Honor2 = ? And Honor3 = ? And Honor4 = ? Limit 0";
$sqlparent = "SELECT Father, EducationalFather, Mother, EducationalMother, Guardian, Occupation From parent Where Father = ? And EducationalFather = ? And Mother = ? And EducationalMother = ? AND Guardian = ? AND Occupation = ? Limit 0";
$INSERTpersonal = "INSERT INTO personal (FirstName, MiddleName, LastName, Age, HomeAddress, ContactNumber, LastSchoolAttended, Strand, SchoolAddress, Adviser) values (?,?,?,?,?,?,?,?,?,?)";
$INSERThonor = "INSERT INTO honor (Honor1,Honor2,Honor3,Honor4) values (?,?,?,?)";
$INSERTparent = "INSERT INTO parent (Father, EducationalFather,Mother,EducationalMother,Guardian,Occupation) values (?,?,?,?,?,?)";
$stmt = $conn->prepare($sql);
$stmthonor = $conn->prepare($sqlhonor);
$stmtparent = $conn->prepare($sqlparent);
$stmt -> bind_param("ssss", $FirstName,$MiddleName,$LastName,$LastSchoolAttended);
$stmthonor -> bind_param("ssss", $Honor1,$Honor2,$Honor3,$Honor4);
$stmtparent -> bind_param("ssssss", $Father,$EducationalFather,$Mother,$EducationalMother, $Guardian, $Occupation);
$stmt -> execute();
$stmthonor -> execute();
$stmtparent -> execute();
$stmt -> bind_result($FirstName,$MiddleName,$LastName,$LastSchoolAttended);
$stmthonor -> bind_result($Honor1,$Honor2,$Honor3,$Honor4);
$stmtparent -> bind_result($Father,$EducationalFather,$Mother,$EducationalMother,$Guardian ,$Occupation );
$stmt -> store_result();
$stmthonor -> store_result();
$stmtparent -> store_result();
$rnum = $stmt -> num_rows;
$rnum = $stmthonor -> num_rows;
$rnum = $stmtparent -> num_rows;
if ($rnum == 0 ) {
$stmt->close();
$stmthonor->close();
$stmtparent->close();
$stmt = $conn -> prepare($INSERTpersonal);
$stmthonor = $conn -> prepare($INSERThonor);
$stmtparent = $conn -> prepare($INSERTparent);
$stmt -> bind_param("sssisissss", $FirstName,$MiddleName,$LastName,$Age,$HomeAddress,$ContactNumber,$LastSchoolAttended,$Strand, $SchoolAddress,$Adviser);
$stmthonor -> bind_param ("ssss", $Honor1, $Honor2, $Honor3, $Honor4);
$stmtparent -> bind_param ("ssssss", $Father, $EducationalFather, $Mother, $EducationalMother, $Guardian, $Occupation);
$stmt -> execute();
$stmthonor -> execute();
$stmtparent -> execute();
}
}
?>
I have my foreign key which is the ExamineeID and I have a trouble from inserting data.