我有以下表格,我尽可能地减少了表格,但没有确定问题的来源。我试图将表单值插入数据库。
然而,当尝试使用下面的表格时,它会吐出:
查询为空
两次。 STATUS表存在,删除和通知的字段也存在。该表目前没有内容。我不明白为什么查询会为空?
<?php
if (isset($_GET["cmd"]))
$cmd = $_GET["cmd"]; else
if (isset($_POST["cmd"]))
$cmd = $_POST["cmd"]; else
die("Invalid URL");
if (isset($_GET["pk"])) {
$pk = $_GET["pk"];
}
if (isset($_POST["deleted"])) {
$deleted = $_POST["deleted"];
}
if (isset($_POST["notice"])) {
$notice = $_POST["notice"];
}
$con = mysqli_connect("localhost","user","password", "db");
if (!$con) {
echo "Can't connect to MySQL Server. Errorcode: %s\n". mysqli_connect_error();
exit;
}
$con->set_charset("utf8");
$getformdata = $con->query("select * from STATUS where ARTICLE_NO = '$pk'");
$checkDeleted = "";
$checkNotice = "";
while ($row = mysqli_fetch_assoc($getformdata)) {
$checkDeleted = $row['deleted'];
$checkNotice = $row['notice'];
}
if($cmd=="submitinfo") {
$statusQuery = "INSERT INTO STATUS VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
if ($statusInfo = $con->prepare($userQuery)) {
$statusInfo->bind_param("ss", $deleted, $notice);
$statusInfo->execute();
$statusInfo->close();
echo "true";
} else {
echo "false";
}
print_r($con->error);
}
if($cmd=="EditStatusData") {
echo "<form name=\"statusForm\" action=\"test.php\" method=\"post\" enctype=\"multipart/form-data\">
<h1>Editing information for auction: ".$pk."</h1>
Löschung Ebay:
<input type=\"checkbox\" name=\"deleted\" value=\"checked\" ".$checkDeleted." />
<br />
Abmahnung:
<input type=\"checkbox\" name=\"notice\" value=\"checked\" ".$checkNotice." />
<br />
<input type=\"hidden\" name=\"cmd\" value=\"submitinfo\" />
<input name=\"Submit\" type=\"submit\" value=\"submit\" />
</form>";
} else {
print_r($con->error);
}
答案 0 :(得分:0)
这里有拼写错误:
$statusQuery = "INSERT INTO STATUS VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
if ($statusInfo = $con->prepare($userQuery)) {
第二行不是$ statusQuery吗?
答案 1 :(得分:0)
尝试将一些内容放入表格中...如果没有任何内容可以返回,则会告诉您查询为空。
答案 2 :(得分:0)
您的作业是
$ statusQuery =“INSERT INTO ....
但您引用了一个名为$ userQuery
的变量if($ statusInfo = $ con&gt; prepare( $ userQuery )){