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

use the die()

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
    ...
}

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

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.
}
?>

Thanks for your help works perfect

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.