will_1990 Posted December 11, 2008 Share Posted December 11, 2008 Hi as some of you may knwo due to my excessive posting on this forum i am making a flights website. I need a pointer in the right direction which will compare two dates that are entered by the user and then anaylise to think if date b if before date a then return an error, is this fairly simple.... even a pointer on what is best to google will help. Here is my code so far (not the form just php) <?php //database inforamtion $host = "stocks"; // Host name $username = "wbennett"; // Mysql username $password = "mysql5"; // Mysql password $db_name = "wbennett"; // Database name $tbl_name1 = "flight_webair"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Variables $flight_route_out = $_POST['flight_route_out']; $flight_route_return = $_POST['flight_route_return']; $date_out = $_POST['departure_date']; $date_return = $_POST['return_date']; $passenger_num = $_POST['num_of_pass']; $one_way = (isset($_POST['one_way'])) ? $_POST['one_way'] : null; // make sure value is available first. //To protect MySQL injection $flight_route_out = stripslashes($flight_route_out); $flight_route_return = stripslashes($flight_route_return); $flight_route_out = mysql_real_escape_string($flight_route_out); $flight_route_return = mysql_real_escape_string($flight_route_return); //Queries $sql1="SELECT * FROM `$tbl_name1` WHERE `flight_route` = '$flight_route_out'"; //$sql="SELECT * FROM $tbl_name1 WHERE flight_route_return='$flight_route_return'"; //Execute query 1 $result = mysql_query($sql1) or die(mysql_error()); if(mysql_num_rows($result) > 0){ ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" href="dropdown2.css" type="text/css" /> <script type="text/javascript" src="dropdown.js"> </script> <script type="text/javascript" src="calendar.js"> </script> <script type="text/javascript" src="enablefield.js"> </script> <title> Booking Confirmation </title> <script type="text/javascript"> function greyText(one_way, return_date) { if (document.form1[one_way].checked) { document.form1[return_date].disabled=true; document.form1[return_flight].disabled=true; } else { document.form1[return_date].disabled=false; document.form1[return_flight].disabled=false; } } <title>Webair Contact Us</title> <link rel="StyleSheet" href="./mainstyle.css"type="text/css" media="screen"> </script> </head> <body> <div id="wrapper"> <table> <tr> <td> <img src="Webair--logo.gif" height= "65" width="240" align="top" /> </td> <td background="Banner--background.gif" height="60" align="right" width="817" > <a class="hyperlink" href="http://www.cems.uwe.ac.uk/~wbennett/webair/main_logon.php"> <b> Staff login </b> </a> | <a class="hyperlink" href="http://www.cems.uwe.ac.uk/~wbennett/webair/index.html" > <b> Home </b> </a> | <a class="hyperlink" href="http://www.cems.uwe.ac.uk/~wbennett/webair/index.html" > <b> Booked Flights   </b> </a> </td> </tr> </table> <dl class="dropdown" > <dt id="one-ddheader" onmouseover="ddMenu('one',1)" onmouseout="ddMenu('one',-1)" > Home </dt> <dd id="one-ddcontent" onmouseover="cancelHide('one')" onmouseout="ddMenu('one',-1)" > <ul> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/index.html" class="underline" > Home </a> </li> </ul> </dd> </dl> <dl class="dropdown" > <dt id="two-ddheader" onmouseover="ddMenu('two',1)" onmouseout="ddMenu('two',-1)" > Contact us </dt> <dd id="two-ddcontent" onmouseover="cancelHide('two')" onmouseout="ddMenu('two',-1)" > <ul> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_contact" class="underline" > Contact us </a> </li> </ul> </dd> </dl> <dl class="dropdown" > <dt id="three-ddheader" onmouseover="ddMenu('three',1)" onmouseout="ddMenu('three',-1)" > Flights </dt> <dd id="three-ddcontent" onmouseover="cancelHide('three')" onmouseout="ddMenu('three',-1)" > <ul> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_refunds.html" class="underline" > Refund Policy </a> </li> </ul> </dd> </dl> <dl class="dropdown" > <dt id="four-ddheader" onmouseover="ddMenu('four',1)" onmouseout="ddMenu('four',-1)" > Travel Information </dt> <dd id="four-ddcontent" onmouseover="cancelHide('four')" onmouseout="ddMenu('four',-1)" > <ul> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_flight_fares.html" class="underline" > Flight Timetable </a> </li> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_baggage.html" class="underline" > Baggage Information </a> </li> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_airport_info.html" class="underline" > Airport information </a> </li> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_travel_info.html" class="underline" > Travel documentation requirements </a> </li> </ul> </dd> </dl> <dl class="dropdown" > <dt id="five-ddheader" onmouseover="ddMenu('five',1)" onmouseout="ddMenu('five',-1)" > About Webair </dt> <dd id="five-ddcontent" onmouseover="cancelHide('five')" onmouseout="ddMenu('five',-1)" > <ul> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_about.html" class="underline" > About Webair </a> </li> <li> <a href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_contact.html" class="underline" > Contact us </a> </li> </ul> </dd> </dl> <div style="clear:both" /> </div> <div id="content" > <div id="table_gen_1" > <div class="inner" > <br> <h1><center> Confirm Booking </center></h1> <h3><b><u> Out-going Flight Information: </u></b></h3> <?php while($row = mysql_fetch_array($result)){ echo " <br><br> <table border='1' cellpadding=10> <tr> <td class='table'> <center><b> Flight Number </b></center> </td> <td class='table'> <center><b> Flight Route Selected </b></center> </td> <td class='table'> <center><b> Departure Time </b> </center> </td> <td class='table'> <center><b> Arrival Time </b></center> </td> <td class='table'> <center><b> Departure Date </b></center> </td> <td class='table'> <center><b> Return Date </b></center> </td> <td class='table'> <center><b> Number of Passengers Selected </b></center> </td> </tr> <tr> <td class='table'> <center> ".$row['flight_num']." </center> </td> <td class='table'> <center> ".$row['flight_route']." </center> </td> <td class='table'> <center> ".$row['departure_time']." </center> </td> <td class='table'> <center> ".$row['arrival_time']." </center> </td> <td class='table'> <center> ".$date_out." </center> </td> <td class='table'> <center> ".$date_return." </center> </td> <td class='table'> <center> ".$passenger_num[num_of_pass]." </center> </td> </tr> </table> <br><br>"; } ?> </div> </div> </div> <div id="footer"> <div id="inner"> <div id="footer2"> <p><hr class="line"></hr> <a class="hyperlink2" href="http://www.cems.uwe.ac.uk/~wbennett/webair/main_logon.php"><b>Staff login</b></a> | <a class="hyperlink2" href="http://www.cems.uwe.ac.uk/~wbennett/webair/index.html"><b>Home</b></a> | <a class="hyperlink2" href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_contact.html"><b>Contact us</b></a> | <a class="hyperlink2" href="http://www.cems.uwe.ac.uk/~wbennett/webair/webair_about.html"><b>About Webair</b></a> <hr class="line2"></hr> </p> </div> </div> </div> </body> </html> <?php }else{ echo 'Sorry, couldn\'t find any flights'; } mysql_free_result($result); ?> Many thanks Will ps i had some help with this and i cannot for the life of me remeber what this code segment means, i know i will need to impliment it very shortly so i thought id add it here as an after thought <?php $one_way = (isset($_POST['one_way'])) ? $_POST['one_way'] : null; // make sure value is available first. ?> as ypou can see from the comment thats what i think its doing, but is that correct. thanks Link to comment https://forums.phpfreaks.com/topic/136543-date-vailidation-function/ Share on other sites More sharing options...
glenelkins Posted December 11, 2008 Share Posted December 11, 2008 $one_way = (isset($_POST['one_way'])) ? $_POST['one_way'] : null; // make sure value is available first. this is basically a simple IF statement. $one_way will become equal to $_POST['one_way'] if $_POST['one_way'] is set, otherwise it will be set to "null" you can compare dates by using strtotime() if ( strtotime ( $date_return ) < strtotime ( $date_out ) ) { echo "error"; } Link to comment https://forums.phpfreaks.com/topic/136543-date-vailidation-function/#findComment-712723 Share on other sites More sharing options...
will_1990 Posted December 11, 2008 Author Share Posted December 11, 2008 $one_way = (isset($_POST['one_way'])) ? $_POST['one_way'] : null; // make sure value is available first. this is basically a simple IF statement. $one_way will become equal to $_POST['one_way'] if $_POST['one_way'] is set, otherwise it will be set to "null" you can compare dates by using strtotime() if ( strtotime ( $date_return ) < strtotime ( $date_out ) ) { echo "error"; } great thanks for your advice, i implimented the code here : // Variables $flight_route_out = $_POST['flight_route_out']; $flight_route_return = $_POST['flight_route_return']; $date_out = $_POST['departure_date']; $date_return = $_POST['return_date']; $passenger_num = $_POST['num_of_pass']; $one_way = (isset($_POST['one_way'])) ? $_POST['one_way'] : null; // make sure value is available first. //To protect MySQL injection $flight_route_out = stripslashes($flight_route_out); $flight_route_return = stripslashes($flight_route_return); $flight_route_out = mysql_real_escape_string($flight_route_out); $flight_route_return = mysql_real_escape_string($flight_route_return); //Queries $sql1="SELECT * FROM `$tbl_name1` WHERE `flight_route` = '$flight_route_out'"; //$sql="SELECT * FROM $tbl_name1 WHERE flight_route_return='$flight_route_return'"; //Execute query 1 $result = mysql_query($sql1) or die(mysql_error()); if ( strtotime ( $date_return ) < strtotime ( $date_out ) ) { echo "error"; } however i does not seem to echo the erorr or even pick up that the date later. this is the form of the date: td> <input type="text" name="return_date" readonly="readonly" value="dd/mm/yy" onfocus="this.select();lcs(this)" onclick="event.cancelBubble=true;this.select();lcs(this)" > </td> thanks alot Link to comment https://forums.phpfreaks.com/topic/136543-date-vailidation-function/#findComment-712735 Share on other sites More sharing options...
will_1990 Posted December 11, 2008 Author Share Posted December 11, 2008 I updated the code to by dd/mm/yyyy but still seems as if the statement is not being run any ideas? Link to comment https://forums.phpfreaks.com/topic/136543-date-vailidation-function/#findComment-712756 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.