好的我有以下代码但是我的sql查询不会显示结果所以我得出结论sql语句一定是错的?
请有人让我知道我做错了什么?
由于
$result=mysqli_query("SELECT * FROM Persons WHERE Day = '".$_POST['Day']."' AND Time = '".$_POST['Time']."'");
echo "Query Runs";
echo "<table border='1'>
<tr>
<th>Name</th>
<th>Day</th>
<th>Time</th>
<th>Reg</th>
</tr>";
echo "Delete a Booking today ";
while($row = mysqli_fetch_array($query))
{
echo "<tr>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['Day'] . "</td>";
echo "<td>" . $row['Time'] . "</td>";
echo "<td>" . $row['Reg'] . "</td>";
echo "</tr>";
}
echo "</table>";
sql语句无效,因为以下命令将运行。 $ result = mysqli_query(“SELECT * FROM Persons WHERE Day ='”。$ _ POST ['Day']。“'AND Time ='”。$ _ POST ['Time']。“'”);
以下都不会返回结果:
$result=mysqli_query("SELECT * FROM Persons WHERE Day = '".$_POST['Day']."' AND Time = '".$_POST['Time']."'";
$result=mysqli_query("SELECT * FROM Persons WHERE Day = '$_POST[Day]' AND Time = '$_POST[Time]' ")
答案 0 :(得分:1)
day
和time
在mysql中保留。
使用返回标记`
,以便它们不会将它们作为保留名称读取,而是作为您的表名称。
$query=mysqli_query("SELECT * FROM Persons WHERE `DAY` = '".$_POST['Day']."' AND `Time` = '".$_POST['Time']."'");
此代码也容易受到sql攻击。请正确使用mysqli
here。
答案 1 :(得分:0)
您忘记执行SQL查询。
$query=mysqli_query("SELECT * FROM Persons WHERE DAY = '".$_POST['Day']."' AND Time = '".$_POST['Time']."'");