Reputation: 383
I have a mysql statement that is giving me an error. It looks right to me but obviously I am missing something and I keep failing to see it. My code is such
$PlusHour = date('gA', strtotime("+1 hours"));
$Plus30 = date('g:30A', strtotime("+1 hours"));
$SearchDate = "CURDATE()";
$sqlCount = "SELECT COUNT (*) FROM ServiceTickets WHERE Date= $SearchDate AND Time= $PlusHour OR Time= $Plus30 AND JobStatus= '1' OR JobStatus= '3' ";
$CountQuery = mysqli_query($db_conx, $sqlCount) or die("Error: ".mysqli_error($db_conx));
$rowCount = mysqli_fetch_row($CountQuery);
The error I get is
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 ServiceTickets WHERE Date= 2018-03-15 AND Time= 11PM OR Time= 11:30PM AN' at line 1
What am I doing wrong here. Is there a problem with how my AND OR is structured?
Upvotes: 1
Views: 43
Reputation: 1966
There is white space in your query at COUNT (*)
.
Please remove that only.
You also need to have quotes around $PlusHour
and $Plus30
Your query will be like,
$query = "SELECT COUNT(*) FROM ServiceTickets WHERE Date= $SearchDate AND Time= '$PlusHour' OR Time= '$Plus30'r AND JobStatus= '1' OR JobStatus= '3' "
Upvotes: 1