Jump to content

[SOLVED] Using 'OR' in my mysql statement


matt.sisto

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/155742-solved-using-or-in-my-mysql-statement/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.