我有一个 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);
最佳答案
我不能因为声誉问题发表评论,所以我必须在回答中给你一个提示:你是否尝试过使用一些接口(interface)直接在你的数据库上使用这个查询?
但是,您可以在关闭连接之前尝试添加一些行以查看错误是什么:
if ($dbcon->query($res_ins) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $res_ins. "<br>" . $dbcon->error;
}
关于php - 使用 PHP 将调查插入 SQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53079787/