0

Hello. I have a problem with my code below, but can't see any issues with it.

I am trying to get all of the appointments from the appointments table, within the dates input by the user and display them in a table. I am getting a Syntax error.

My mysql query is as follows:

$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);
Ranty
  • 3,333
  • 3
  • 22
  • 24
  • my while loop looks a little like this, with a few more statements: { echo ""; echo "" . $row['Appointment_No'] . ""; echo "" . $row['Appointment_Date'] . ""; echo "" . $row['Appointment_Time'] . ""; echo "".$pid.""; echo ""; } – Tim Butterfield Feb 14 '13 at 15:50

2 Answers2

0

date are enclosed with single quotes,

$result = mysql_query("
        SELECT  * 
        FROM   appointment 
        WHERE  Appointment_Date BETWEEN '$fromDate' AND '$toDate' 
               AND Practice_ID = '$prac' 
        ORDER  BY Appointment_Time");

As a sidenote, the query is vulnerable with SQL Injection if the value(s) of the variables came from the outside. Please take a look at the article below to learn how to prevent from it. By using PreparedStatements you can get rid of using single quotes around values.

Community
  • 1
  • 1
John Woo
  • 258,903
  • 69
  • 498
  • 492
0

You are missing a bracket here:

while ($row = mysql_fetch_array($result); // << 2 brackets needed at the end

And instead of semicolon you need a proper while loop.

while(...)
{
    // do something
}
Ranty
  • 3,333
  • 3
  • 22
  • 24
  • thanks I've got the page to load at least now due to missing bracket. My while loop statement is too many characters long to post! – Tim Butterfield Feb 14 '13 at 15:47
  • I suggest finding where your server has it's php error logs. You then will be able to see the exact error reasons. I would say something like "unexpected semicolon" and the error line, which is a clear pointer on where is the problem. – Ranty Feb 14 '13 at 15:53