matt.sisto Posted April 26, 2009 Share Posted April 26, 2009 Hi all, I am trying to check the availability of a consultant on a booking form, and a booking can have up to 3 consultants therefore the sql statement needs to compare the selected consultant to the 3 possible rows. I have written the code and it doesn't like the 'OR' in my sql statement. Here is my code: <?php session_start(); if (!isset($_SESSION['username'])) { header("Location: login.php"); exit(); } require "dbconn2.php"; $month = mysql_real_escape_string($_POST["month"]); $day = mysql_real_escape_string($_POST["day"]); $year= mysql_real_escape_string($_POST["year"]); $con_id= mysql_real_escape_string($_POST["con_id"]); $event_start = $year."-".$month."-".$day." ".$_POST["event_start"]; $sql = "SELECT * FROM calendar_events WHERE event_start='".$event_start."' AND con_1='".$con_id."', OR con_2='".$con_id."',OR con_3='".$con_id."'"; $result = mysql_query ($sql, $connection) or die ("Could not perform query $sql <br />".mysql_error()); $row = mysql_fetch_array($result); if ($row != null){ $url = "Location: bookingform.php?available=false"; header($url); } else { $url = "Location: bookingform.php?available=true"; header($url); } ?> Appreciate any advice. Thanks and regs. Quote Link to comment https://forums.phpfreaks.com/topic/155742-solved-using-or-in-my-mysql-statement/ Share on other sites More sharing options...
Mchl Posted April 26, 2009 Share Posted April 26, 2009 You have unneeded commas, and don't have needed parentheses. The condition should look like this: WHERE event_start=? AND (con_1=? OR con_2=? OR con_3=?) Quote Link to comment https://forums.phpfreaks.com/topic/155742-solved-using-or-in-my-mysql-statement/#findComment-819787 Share on other sites More sharing options...
matt.sisto Posted April 26, 2009 Author Share Posted April 26, 2009 Thanks, that is sorted now. Quote Link to comment https://forums.phpfreaks.com/topic/155742-solved-using-or-in-my-mysql-statement/#findComment-819788 Share on other sites More sharing options...
Mchl Posted April 26, 2009 Share Posted April 26, 2009 Just FYI: this table does not seem normalised. Are you aware of that? Quote Link to comment https://forums.phpfreaks.com/topic/155742-solved-using-or-in-my-mysql-statement/#findComment-819789 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.