This question already has an answer here:
I'm creating a questionnaire site that asks for the users information and asks questions and sends that data to a database.
What my database looks like:
Relationship view of Question Table
Me failing to insert my data to the database:
if (isset($_POST['save']))
{
$q1 = $_POST['q1'];
$q2 = $_POST['q2'];
$q3a = $_POST['q3a'];
$q3b = $_POST['q3b'];
$q3c = $_POST['q3c'];
$q3d = $_POST['q3d'];
$q3e = $_POST['q3e'];
$q3f = $_POST['q3f'];
$age = $_POST['age'];
$gender = $_POST['gender'];
$work = $_POST ['work'];
$name = $_POST['name'];
$contact = $_POST['contact'];
mysqli_query($conn, "INSERT INTO customer (cust_name, cust_hp, age, sex, work) VALUES ('$name','$contact','$age', '$gender', '$work')");
mysqli_query($conn, "INSERT INTO question (Q1, Q2, Q3a, Q3b, Q3c, Q3d, Q3e, Q3f) VALUES ('$q1', '$q2', '$q3a', '$q3b', '$q3c', '$q3d', '$q3e', '$q3f')");
header('location: index.php');
}
Current result: everytime I click submit the only the customer details table is updated. If I drop the foreign key restraint and the fk_cust column both tables update without any problem.
My question is how to setup foreign keys so that when I run those two querys my cust_id in customer table and my fk_cust id in the questions table are 'connected'.
Thanks in advanced kind stranger. Apologies if this has been talked to death.
</div>