I wan't to create a validation, check the database if the DATE, TIME and COTTAGE is already reserved/available. If any in one of the 3 is unavailable, it will save to the database.
Here is the code I made:
<?php
require_once("config.php");
require_once("includes/inputs.php");
//fetching the data of the cottage
$sql = "SELECT * FROM cottage WHERE id='$cottage'";
$result = mysqli_query($link, $sql);
$row = mysqli_fetch_array($result);
$name_cottage = $row["name"];
//fetching the data of the time
$sql = "SELECT * FROM rate WHERE id='$daytime'";
$result = mysqli_query($link, $sql);
$row = mysqli_fetch_array($result);
$daytime_name = $row["name"];
//validating whether the date, time and cottage is already available in the cottage
$validate = "SELECT * FROM reserve WHERE date = '$date' AND daytime = '$daytime' AND cottage = '$cottage'";
$qry = mysqli_query($link, $validate);
$getrow = mysqli_num_rows($qry);
if( $getrow > 0 ){
echo " $date, $daytime_name and $name_cottage has already been taken!";
return false;
}
else{
$sql = "INSERT into reserve (name, address, contact, email, date, time, ahc, chc, cottage, promo, total) values ('$name','$address','$contact', '$email', '$date', '$daytime', '$ahc', '$chc', '$cottage', '$promo', '$calc')";
$result = mysqli_query($link,$sql);
echo " $date, $daytime_name and $name_cottage is successfully reserved!";
return true;
}
?>
But i am having an error of:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\reservation\formup.php on line 22
and line 22 is
$getrow = mysqli_num_rows($qry);
but when i use this multiple select query:
$validate = "SELECT * FROM reserve WHERE date = '$date'";
$validate = "SELECT * FROM reserve WHERE daytime = '$daytime'";
$validate = "SELECT * FROM reserve WHERE cottage = '$cottage'";
it will save to the database but when the cottage have the same cottage on the database it won't save...
please help me to fix this....