Im inserting information in the first table then getting InsertID for the foreign key for the second table to tie the records together. The second table will not insert and
if(isset($_POST['submit']))
{
$date = $_POST['txt_date'];
$hospital = $_POST['hospital_dd'];
//prepare statement
$stmt = $conn->stmt_init();
//sql
$sql = "INSERT INTO Brucella (ClientName, PatientName,IDNumber,Age,AgeType,Sex,Doctor,Results,TestId) values (?,?,?,?,?,?,?,?,?)";
$sqlTest = "Insert Into BrucellaTest (DateReported, DateSubmitted, Technician, Samples) values (?,?,?,?)";
if($_POST['hospital_dd'] >= 1){
if(isset($_GET['TestId']) ){
$TheTestId = $_GET['TestId'];
$sqlUpdate = "Update BrucellaTest set DateReported = ?, DateSubmitted = ?, Technician = ?, Samples=? where Id ='$TheTestId'";
$stmt->prepare($sqlUpdate);
$stmt->bind_param('sssi',$_POST['date_reported'],$_POST['txt_date'],$_POST['tech'],$_POST['samples']);
$stmt->execute();
$InsertId = $_GET['TestId'];
}else
{
$stmt->prepare($sqlTest);
$stmt->bind_param('sssi',$_POST['date_reported'],$_POST['txt_date'],$_POST['tech'],$_POST['samples']);
$stmt->execute();
$InsertId = $stmt->insert_id;
}
}
if($stmt->prepare($sql)){
//bind parameters
$stmt->bind_param('ssssssssi', $_POST['hospital_dd'],$_POST['txt_patient_name'], $_POST['txt_id'],$_POST['txt_age'],$_POST['age_value'],$_POST['sel_sex'],$_POST['txt_doctor'],$_POST['sel_results'], '$InsertId');
$stmt->execute();
}
}
?>