Reputation: 167
I'm working on a final project for a PHP class and I'm having trouble with validating the code. In the else if part of the code I always get an error at both of these else if statements and the application stops processing. The code below is a part of a .php file that has a HTML form for setting reminders.
} else if (!checkdate($_POST['reminderMonth'],$_POST['reminderDate'],$_POST['remindereEar'])) {
$error_message = "Selected date does not exist.";
} else if ($reminderDate <= $t_date) {
$error_message = "Selected date has already occured.";
All of the code:
if(isset($_POST['submit'])) {
//get data
$t_date = date(Ymd);
$year = $_POST['reminderYear'];
$month = $_POST['reminderMonth'];
$day = $_POST['reminderDay'];
//validate data
$reminderDate = $year.$month.$day;
if (empty($_POST['reminderName'])) {
$error_message = "Name is a required field.";
} else if (!checkdate($_POST['reminderMonth'],$_POST['reminderDate'],$_POST['remindereEar'])) {
$error_message = "Selected date does not exist.";
} else if ($reminderDate <= $t_date) {
$error_message = "Selected date has already occured.";
} else {
$error_message = ''; }
//redirect
if(empty($error_message)) {
mysql_query("INSERT INTO reminder_event
(reminderName,reminderDescript,reminderDate)
VALUES
('{$reminderName}','{$reminderDescript}','{$reminderDate}')");
header("Refresh: 1;url=reminder_list.php");
} else {
echo($error_message); } }
Upvotes: 1
Views: 86
Reputation: 285
date(Ymd) will produce error should be
date('Y m d');
and make sure $reminderDate = $year.$month.$day; is formatted in the same way
$reminderDate = $year.' '.$month.' '.$day;
Also 2 typos:
$_POST['reminderDate'],$_POST['remindereEar']
Dont know if this is a solution, but still looks like it will cause problems if you run it your way
Upvotes: 1
Reputation: 28144
You made a mistake with reminderDate and remindereEar.
It should be instead : $_POST['reminderDay'], $_POST['reminderYear']
Tell me if you get more error after changing that.
Upvotes: 1
Reputation: 6389
I see 2 typos:
$_POST['reminderDate'],$_POST['remindereEar']
It should be:
$_POST['reminderDay'],$_POST['reminderYear']
Upvotes: 1