Table reservations on desired days, but if the table is reserved for a specific day that the user inputs, then the program should spit out that that table is reserved for that date.
Steps i took:
1. Connect to database
2. Receive user data from form (table and date)
3. Compare user data to mysql database table & date rows
4. If there is equal data on the table and date rows to what the user submitted, echo "Unavailable"
5. But if its not equal echo "Available"
I hope this helps, thanks for your help
Code: Select all
<?php require_once('../Connections/Reservations.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$maxRows_checkorders = 10;
$pageNum_checkorders = 0;
if (isset($_GET['pageNum_checkorders'])) {
$pageNum_checkorders = $_GET['pageNum_checkorders'];
}
$startRow_checkorders = $pageNum_checkorders * $maxRows_checkorders;
mysql_select_db($database_Reservations, $Reservations);
$query_checkorders = "SELECT orders.tablenumber, orders.`date` FROM orders";
$query_limit_checkorders = sprintf("%s LIMIT %d, %d", $query_checkorders, $startRow_checkorders, $maxRows_checkorders);
$checkorders = mysql_query($query_limit_checkorders, $Reservations) or die(mysql_error());
$row_checkorders = mysql_fetch_assoc($checkorders);
if (isset($_GET['totalRows_checkorders'])) {
$totalRows_checkorders = $_GET['totalRows_checkorders'];
} else {
$all_checkorders = mysql_query($query_checkorders);
$totalRows_checkorders = mysql_num_rows($all_checkorders);
}
$totalPages_checkorders = ceil($totalRows_checkorders/$maxRows_checkorders)-1;
$table = $_POST['table'];
$redate = $_POST['ADate'];
if ($table && $redate){
} else {
print "Not submitted";
}
while ($row_checkorders = mysql_fetch_assoc($checkorders)){
echo 'While loop entered.<br />';
if ($_POST['table'] == $row_checkorders['tablenumber'] && $_POST['ADate'] == $row_checkorders['date']){
echo 'If statement TRUE.<br />';
print "Table $table is unavailable for $redate. Please select another table or another day.";
} else {
echo 'If statement FALSE.<br />';
print "Available";
}
}
// PROBLEM HERE >>>>>>>>>>>>>>>
while ($row_checkorders = mysql_fetch_assoc($checkorders)){
if ($_POST['table'] == $row_checkorders['tablenumber'] && $_POST['ADate'] == $row_checkorders['date']){
print "Table $table is unavailable for $redate. Please select another table or another day.";
} else {
print "Available";
}
}
//This didnt work either
/*
do {
if ($_POST['table'] == $row_checkorders['tablenumber'] && $_POST['ADate'] == $row_checkorders['date']){
print "Table $table is unavailable for $redate. Please select another table or another day.";
} else{
print "Available";
}
} while ($row_checkorders = mysql_fetch_assoc($checkorders));
*/
?>
</body>
</html>
<?php
mysql_free_result($checkorders);
?>