I'm new to php and mysql, but I have a mysql table setup and several files that allow the user to correctly insert, update and delete records from the table. All these functions are currently working properly.
The problem I'm having is that I have a need to do a check based on querying the table for the SUM() of a given field (tix) based on the $tourdate variable and then do a compare on it.
In other words, I was trying to setup something like this:
<?
$resdate = $POST['resdate'];
$tourdate = $POST['tourdate'];
$fname = $POST['fname'];
$lname = $POST['lname'];
$address = $POST['address'];
$city = $POST['city'];
$st = $POST['st'];
$zip = $POST['zip'];
$phone = $POST['phone'];
$altphone = $POST['altphone'];
$email = $POST['email'];
$howheard = $POST['howheard'];
$tix = $POST['tix'];
$cc = $POST['cc'];
$ccexp = $POST['ccexp'];
$mailtype = $POST['mailtype'];
// script to display all the records in a table
include('conn.php');
$query = "select SUM(tix) AS num_tix FROM table WHERE tourdate='$tourdate'";
if(num_tix > 25)
{
echo "There are no reservations available for this tour date and time.";
}
elseif (tix > 25)
{
echo "You have entered too many reservations for this tour.";
}
else
{
// Insert Data into table
$query = "INSERT INTO haunted (resdate, tourdate, fname, lname, address, city, st, zip, phone, altphone, email, howheard, tix, cc, ccexp, mailtype) VALUES ('$resdate', '$tourdate', '$fname', '$lname', '$address', '$city', '$st', '$zip', '$phone', '$altphone', '$email', '$howheard', '$tix', '$cc', '$ccexp', '$mailtype')";
$result = mysql_query($query);
// Close the database connection
mysql_close();
echo "Your reservation has been submitted to the database.<br /><br />Click <a href='display.php'>here</a> to review your additions.";
}
?>
but all I seem to get is the INSERT statement to execute......
any ideas on what I'm missing?
Thanks!
C.