0

This is my code to match with existing booking date to check that available sport on the particular date or not but not working please help

if(isset($_POST['check']))
{   
    $sportName = mysqli_real_escape_string($con, $_POST['game']);
    $bookDate = mysqli_real_escape_string($con, $_POST['date_of_booking']);
    $result = mysqli_query($con,"
SELECT sport_name 
  FROM booking 
 WHERE booking_date='$bookDate'
");     

        if($result == $sportName) 
        {
            echo "Sorry this Sport is booked on selected date by someone else";
        }
        else
        {                   
                echo "Availabe ";                   
        }   
}
ArK
  • 20,698
  • 67
  • 109
  • 136
Fazam
  • 1
  • 2
  • What gives `echo $bookDate` ? – Michael May 20 '17 at 17:23
  • how are you storing the booking date? in what format? Timestamp? Date? DateTime? – rackemup420 May 20 '17 at 17:48
  • also mysql functions are deprecated. http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php/20767765#20767765 – rackemup420 May 20 '17 at 17:49
  • @rackemup420 what are you talking about? – Strawberry May 20 '17 at 21:19
  • See about parameterised queries – Strawberry May 20 '17 at 21:20
  • @rackemup420 this isn't using mysql_ functions, it's using mysqli_. – ADyson May 23 '17 at 11:13
  • @Fazam is $bookDate the value you expect? Is it in the correct format (YYYY-MM-DD might be best, so as not to be ambiguous)? Does it include time? Is there definitely a matching date in the table? On the face of it, this code should work, but there is a lot of other info needed in order to know what's going wrong. Also, I don't think you can directly compare $result to $sportName. $sportName is a string, `whereas` $result is a `mysql_result` - you need to fetch the data and then read the correct field. See any basic tutorial online for how to do this. – ADyson May 23 '17 at 11:17

0 Answers0