I am having trouble getting this code to work, and was wondering if
someone could tell me what I am doing wrong.
--------------------------------------
CODE--------------------------------------
if (isset($_POST['submitted'])) {
require_once("d atabase.php");
$appt_date = $_POST['appt_month'] . '/' . $_POST['appt_day'] . '/' .
$_POST['appt_year'];
$phone = $_POST['phone1'] . '-' . $_POST['phone2'] . '-' .
$_POST['phone3'];
$appt_time = $_POST['appt_time'];
$query = "SELECT appt_date, appt_time FROM pest_control WHERE
appt_date = " . "'" . $appt_date . "' and appt_time =" . "'" .
$appt_time . "'";
$result = mysql_query ($query);
$rDate = $row['appt_date'];
$rTime = $row['appt_time'];
print $rDate;
print $rTime;
$num = mysql_num_rows( $result);
print $num;
//echo $num . " Number of rows returned<br>\n" ;
//if ($row != mysql_fetch_arr ay ($result)) {
//while ($row != mysql_fetch_arr ay ($result)) {
if ($num == 0)
{
$query = "INSERT INTO pest_control (appt_date, appt_time,
appt_type, name, address1, address2, city, state, zip, phone,
cross_streets)
VALUES ("."'" . $appt_date . "', "."'" .
$_POST['appt_time'] . "', "."'" . $_POST['appt_type'] . "', "."'" .
$_POST['name'] . "',
"."'" . $_POST['address1'] . "', "."'" .
$_POST['address2'] . "', "."'" . $_POST['city'] . "',
"."'" . $_POST['state'] . "', "."'" . $_POST['zip'] . "',
"."'" . $phone . "',
"."'" . $_POST['cross_streets'] . "')";
$result = mysql_query ($query); // Execute the query.
mysql_close($co nn); // Close the database connection.
exit;
}
elseif ($appt_date == $rDate) //Check for conflicting
appointment date
{
echo "We're sorry that appointment date is unavailable, please
select another date.";
user_form_resub mit();
}
elseif ($appt_date == $rTime) //Check for conflicting appoitment
time
{
echo "We're sorry that appointment time is unavailable, please
select another time.";
user_form_resub mit();
}
elseif ($appt_date == $rDate || $appt_time == $rTime) //Check for
conflicting date and time
{
echo "<h3 align='center'> We're sorry that appointment date and time
are already scheduled, please select another date and time.</h3>";
user_form_resub mit();
}
}
}
------------------------------END
CODE---------------------------------------
What I am trying to do is run a query against my database to see if a
appointment time and date are already scheduled, then set the
variables $rDate and $rTime from the query I ran to check those
values.
When I print the number of rows it returns 1, telling me that this
date and time are already scheduled, but then my forms loads again but
doesn't display my message about the conflicting date and time.
I don't get anything returned when I try to print the $rDate and
$rTime to screen.
Any help is appreciated.
Thank you in advance for your assistance.
~John
someone could tell me what I am doing wrong.
--------------------------------------
CODE--------------------------------------
if (isset($_POST['submitted'])) {
require_once("d atabase.php");
$appt_date = $_POST['appt_month'] . '/' . $_POST['appt_day'] . '/' .
$_POST['appt_year'];
$phone = $_POST['phone1'] . '-' . $_POST['phone2'] . '-' .
$_POST['phone3'];
$appt_time = $_POST['appt_time'];
$query = "SELECT appt_date, appt_time FROM pest_control WHERE
appt_date = " . "'" . $appt_date . "' and appt_time =" . "'" .
$appt_time . "'";
$result = mysql_query ($query);
$rDate = $row['appt_date'];
$rTime = $row['appt_time'];
print $rDate;
print $rTime;
$num = mysql_num_rows( $result);
print $num;
//echo $num . " Number of rows returned<br>\n" ;
//if ($row != mysql_fetch_arr ay ($result)) {
//while ($row != mysql_fetch_arr ay ($result)) {
if ($num == 0)
{
$query = "INSERT INTO pest_control (appt_date, appt_time,
appt_type, name, address1, address2, city, state, zip, phone,
cross_streets)
VALUES ("."'" . $appt_date . "', "."'" .
$_POST['appt_time'] . "', "."'" . $_POST['appt_type'] . "', "."'" .
$_POST['name'] . "',
"."'" . $_POST['address1'] . "', "."'" .
$_POST['address2'] . "', "."'" . $_POST['city'] . "',
"."'" . $_POST['state'] . "', "."'" . $_POST['zip'] . "',
"."'" . $phone . "',
"."'" . $_POST['cross_streets'] . "')";
$result = mysql_query ($query); // Execute the query.
mysql_close($co nn); // Close the database connection.
exit;
}
elseif ($appt_date == $rDate) //Check for conflicting
appointment date
{
echo "We're sorry that appointment date is unavailable, please
select another date.";
user_form_resub mit();
}
elseif ($appt_date == $rTime) //Check for conflicting appoitment
time
{
echo "We're sorry that appointment time is unavailable, please
select another time.";
user_form_resub mit();
}
elseif ($appt_date == $rDate || $appt_time == $rTime) //Check for
conflicting date and time
{
echo "<h3 align='center'> We're sorry that appointment date and time
are already scheduled, please select another date and time.</h3>";
user_form_resub mit();
}
}
}
------------------------------END
CODE---------------------------------------
What I am trying to do is run a query against my database to see if a
appointment time and date are already scheduled, then set the
variables $rDate and $rTime from the query I ran to check those
values.
When I print the number of rows it returns 1, telling me that this
date and time are already scheduled, but then my forms loads again but
doesn't display my message about the conflicting date and time.
I don't get anything returned when I try to print the $rDate and
$rTime to screen.
Any help is appreciated.
Thank you in advance for your assistance.
~John
Comment