当我点击提交按钮时,推算数据应该进入下面的查询,但事实并非如此。
似乎正在使用按钮的值。
有人能弄明白为什么它不起作用。它与我的登录页面使用相同的代码,并且有效。
它转到if语句的else部分
错误:
Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM test_set WHERE Room_Code='room'' at line 1
查询:
if (isset($_POST['room']))
{
require "connect.php";
if (count($_POST) > 0)
{
$result = mysqli_query($conn, "SELECT id, FROM test_set WHERE Room_Code='" . $_POST["room"] . "'");
if (!$result) {
printf("Error: %s\n", mysqli_error($conn));
exit();
}
$row = mysqli_fetch_array($result);
if (is_array($row))
{
$_SESSION["Room_ID"] = $row['id'];
header("Location: ../views/student/question.php?id='" . $_SESSION["Room_ID"] . "'");
}
else
{
echo "No";
}
}
}
表格:
<form method="POST" name="room" action="../../config/functions.php">
<label for="room" class="sr-only">Room Code</label>
<input type="text" id="room" name="room" class="form-control" placeholder="Please Enter Room Code">
<br>
<input type="submit" class="waves-effect waves-light btn blue darken-3" name="room" value="room">
</form>
修改
仍然没有以这种方式改变:
$result = mysqli_query($conn, "SELECT id FROM test_set WHERE Room_Code='" . $_POST["room"] . "'");
答案 0 :(得分:4)
从查询中删除,
:
SELECT id ,
$result = mysqli_query($conn, "SELECT id FROM test_set
WHERE Room_Code='" . $_POST["room"] . "'");
答案 1 :(得分:1)
使用按钮的值是因为您为提交按钮指定的名称是“room”:您用于输入文本的名称。从提交按钮中删除name属性,它应该可以工作。
编辑后
更改
header("Location: ../views/student/question.php?id='" . $_SESSION["Room_ID"] . "'");
到
header("Location: ../views/student/question.php?id=" . $_SESSION["Room_ID"]);
您不必在查询字符串中引用变量