0

Hi Guys

I'm using a form which sends data to a php file so that ti can be sent to a database. However some of the data passed are dates for the start, end of teh event and when sign ups expire. I want to stop the from data been sent to the database if the start date is after the end date and if the start date is after the expiry date. AS of yet I can't stop it been written to the database but it does redirect. Tthis is what i have so far for the if function

 $sitename = $_POST[eName];
   $title = $_POST[eName];
   $sDate = $_POST[sDate];
   $enDate = $_POST[enDate];
   $exDate = $_POST[exDate];
   $desc = $_POST[desc];
   $pName = $_POST[eName];

   if ($sDate>$enDate){
  header( 'Location: sign_up_create.php' );
}
    if ($sDate<$exDate){
header( 'Location: sign_up_create.php' );
}

Thanks in advance

4
Contributors
5
Replies
16
Views
4 Years
Discussion Span
Last Post by bfitzgerald
0

The form data is being sent to the database only when you execute a query. So after collecting the data first check the dates and only if within the range, connect to the database and execute the query.

if($sDate < $enDate && $sDate > $exDate) {

    // connect to the database and execute the query
    ...

} else {

    // do something else, i.e. redirect
    ...
}
0

It seems like you are executing the code that inserts the records to the database, before even first checking if the condition is met. Your insert code should be within the corresponding if statements

0

You should do something like this;

<?php 
 if ($sDate>$enDate){
  header( 'Location: sign_up_create.php' );
}
    if ($sDate<$exDate){
// code to execute, ie; the insert code.
}
?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.