"SELECT * FROM reservation WHERE roomnum = {$room['roomnum']}
AND roomtype = {$room['roomtype']}
AND (dateout NOT BETWEEN '$start' AND '$end'
OR datein NOT BETWEEN '$start' AND '$end')"
When I run this query I get the following error:
You have an error in your SQL syntax;
check the manual that corresponds to
your MySQL server version for the
right syntax to use near ‘AND (dateout
NOT BETWEEN ‘2010-11-22’ AND
‘2010-11-30′ OR datei’ at line 3
I have tried reformatting this query for a while (using () and removing the statements that come before the NOT BETWEEN statements). The end result is always a syntax error. Is there an issue with running two betweens?
Thanks,
Ryan
I think you probably have to start debugging this kind of error by dumping the full sql and try it yourself using mysql client when you don’t understand why it is not working.
I would do
and I think it’s going to be obvious what is wrong.
Plus like I said in my comment if you don’t escape the
$roomarray, this code would suffer from sql injection vulnerabilities. You have better to use some parameterized queries, for your reference. Plus prepared statement performs better and make the code more readable in my honest opinion.