doufu1504 2018-09-30 20:20
浏览 60

使用INSERT发送数据时外键不更新[重复]

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:

Customer table

Questions table

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>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 ogg dd trandata 报错
    • ¥15 高缺失率数据如何选择填充方式
    • ¥50 potsgresql15备份问题
    • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
    • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
    • ¥60 pb数据库修改与连接
    • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
    • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
    • ¥20 神经网络Sequential name=sequential, built=False
    • ¥16 Qphython 用xlrd读取excel报错