【发布时间】:2018-10-31 17:22:11
【问题描述】:
我有一个 HTML 调查。我正在用 PHP 处理它,并用 PHP 将它传递到 MySQl 数据库中。在这部分代码之前,我发布了每个输入,并将其作为摘要回显。摘要中的每个输入都正确读取,因此表单似乎工作正常。我手动输入 1 个数据集来测试数据库列,然后 1 组数据直接从表单进入数据库,没有问题。但是,现在我尝试插入另一组数据,但它没有上传。
我列出了每个字段,因为我有另一个字段是插入行时的自动增量。在我之前做的表单句柄上,我还有一个自动增量字段,它在插入过程中没有包含它,它工作得很好,所以我很确定我不需要在这里包含它。
插入代码中是否有我忽略的内容?我可以手动输入与我在调查字段中输入的内容完全匹配的结果,但从调查提交到数据库的数字上传尚未完成。我已连接到数据库,因为我有一个未弹出的连接设置失败错误(它与 $dbcon 配对。$dbcon 代表数据库连接)。
//Data Insertion
$res_ins = "INSERT INTO Survey (name, zip,
gender, income, savings, disaster, work,
res_road, work_road, evacuation, lodging,
injury, children, num_child, educ, city_prep,
PrepComments, emer_res, info, prep, fut_prep)
VALUES ('$name', '$zip', '$gender', '$income',
'$savings', '$disaster', '$work', '$res_road',
'$work_road', '$evacuation', '$lodging',
'$injury', '$children', '$num_child', '$educ',
'$city_prep', '$PrepComments', '$emer_res',
'$info', '$prep', '$fut_prep')";
$insert = $dbcon->query($res_ins);
//Terminate connection to database and end
insertion
mysqli_close($dbcon);
【问题讨论】:
-
失败时有哪些错误?你在验证你的数据吗?使用 print_r() 导出你的最终 sql 语句并查看它。
-
这是一个链接,您可以在其中找到解决方案here