您好。我的代码在下面有问题,但看不出任何问题。
我正在尝试从约会表中获取用户输入的日期内的所有约会,并将它们显示在表格中。我收到语法错误。
我的mysql查询如下:
$result = mysql_query("SELECT * FROM appointment
WHERE Appointment_Date BETWEEN $fromDate AND $toDate
AND Practice_ID = '$prac' ORDER by Appointment_Time");
while ($row = mysql_fetch_array($result);
答案 0 :(得分:0)
日期用单引号括起来
$result = mysql_query("
SELECT *
FROM appointment
WHERE Appointment_Date BETWEEN '$fromDate' AND '$toDate'
AND Practice_ID = '$prac'
ORDER BY Appointment_Time");
作为旁注,如果变量的值( s )来自外部,则查询易受SQL Injection
攻击。请查看下面的文章,了解如何防止它。通过使用PreparedStatements
,您可以摆脱在值周围使用单引号。
答案 1 :(得分:0)
你在这里缺少一个括号:
while ($row = mysql_fetch_array($result); // << 2 brackets needed at the end
而不是分号,你需要一个适当的while循环。
while(...)
{
// do something
}