Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Date Variable is Changing to 31 Dec 1969

Posted on 2008-10-07
4
Medium Priority
?
484 Views
Last Modified: 2012-06-21
Hi all

I have a javascript contact form on a php page.
The javascript is used to verify the field entries (which it does fine). the php file handles the creation of the outgoing emai, and formatting into a table layout.

The issue is with two of the fields - a departure and an arrival date.

Regardless of what is submitted through the form, the output is always Wed 31 Dec 1969.
I'm sure that this is something really simple.
Can anyone help, please?

Thanks

(the file is below)
<?php
 
$ref = $_SERVER['HTTP_REFERER'];
 
$ar="";
 
$dep ="";
 
if(preg_match("(agneswaters.net.au\/agneswater_enquiries\/index.php)",$ref)){
 
extract($_POST);
 
$er[100];
 
 
 
if ($FName!=''){
 
if(!preg_match("/^[a-zA-Z]+$/",$FName)){
 
$er[]="Please use only alpha characters in First Name ";
 
}
 
}else{
 
$er[]="First Name is required";
 
}
 
 
 
if ($LName!=''){
 
if(!preg_match("/^[a-zA-Z]+$/",$LName)){
 
$er[]="Please use only alpha characters in Last Name ";
 
}
 
}
 
	
 
$ar = $ArrMM  . "/" . $ArrDD . "/" . $ArrYY;
 
$dep = $DepMM . "/" . $DepDD  . "/" . $DepYY;
 
$ar =date('m/d/Y',strtotime($ar));
 
$dep =date('m/d/Y',strtotime($dep));
 
if ($dep<=$ar){
 
$er[]="Departure date must be after arrival date";
 
}
 
 
 
if ($Country!=''){
 
if(!preg_match("/^[a-zA-Z]+$/",$Country)){
 
$er[]="Country is required must only have Alphabets";
 
}}else{
 
$er[]="Country is required";
 
}
 
 
 
 
 
if ($email!=''){
 
if(!preg_match("/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/",$email)){
 
$er[]="Please enter valid email";
 
}
 
}else{
 
$er[]="Email is required";
 
}
 
 
 
if ($Phone!=''){
 
if(!preg_match("/^\d+$/",$Phone)){
 
$er[]="Phone Number must not contain alpha characters";
 
}
 
}
 
else{
 
$er[]="Phone Number is required";
 
}
 
 
 
 
 
if ($MPhone!=''){
 
if(!preg_match("/^\d+$/",$MPhone)){
 
$er[]="Mobile Number must not contain alpha characters";
 
}
 
}
 
$add = trim(strip_tags($AddInf));
 
if ($add!=''){
 
if(preg_match("(http:|ftp|http:\/\/|https:\/\/|www.|.com|.net)",$add)){
 
$er[]="Comment / Feedback must not contain URL or any other HTML Tag";
 
}
 
}
 
if ($captcha==''){
 
$er[]="Security Code is required";
 
}elseif ($captcha!=''){
 
if ($captcha!=$cap2){
 
$er[]="Please enter correct Security code";
 
}
 
}
 
 
 
if (count($er)>0){
 
echo "Please Correct the following Errors<br><ul>";
 
foreach ($er as $e){
 
echo "<li>$e</li>";
 
}
 
echo "</ul>";
 
exit;
 
}else{
 
$msg='<style>
 
.stl td{
 
font-family:Arial, Helvetica, sans-serif;
 
font-size:12px;
 
background-color:#F4F4F4;
 
}
 
</style>
 
           <table width="703" border="0" align="center" cellpadding="3" cellspacing="2" class="stl">
 
  <tr>
 
    <td colspan="4" style="background-color:#999999;"><strong>Enquiry From Website </strong></td>
 
  </tr>
 
  <tr>
 
    <td width="132" >First Name </td>
 
    <td width="222" >' . $_POST['FName'] . '</td>
 
    <td width="118" >Last Name </td>
 
    <td width="197" >' . $_POST['LName'] . '</td>
 
  </tr>
 
  <tr>
 
    <td >Town</td>
 
    <td >' . $_POST['Town'] . '</td>
 
    <td >Country</td>
 
    <td >' . $_POST['Country'] . '</td>
 
  </tr>
 
  <tr>
 
    <td >Arriving Date </td>
 
    <td >' . date("D d, M Y",strtotime($ar)) . ' </td>
 
    <td >Departing</td>
 
    <td >' . date("D d, M Y",strtotime($dep))  . ' </td>
 
  </tr>
 
  <tr>
 
    <td >Number of Persons </td>
 
    <td >' . $_POST['NumPers'] . '</td>
 
    <td >Email</td>
 
    <td >' . $_POST['email'] . '</td>
 
  </tr>
 
  <tr>
 
    <td >Phone Number </td>
 
    <td >' . $_POST['Phone'] . '</td>
 
    <td >Mobile Number </td>
 
    <td >' . $_POST['MPhone'] . '</td>
 
  </tr>
 
  <tr>
 
    <td colspan="4" >Additional Information or Question </td>
 
  </tr>
 
  <tr>
 
    <td colspan="4" >' . $_POST['AddInf'] . '</td>
 
  </tr>
 
</table>
 
';
 
$to = 'steve@agneswaters.com.au';
 
$subject = 'Enquiry from Agnes Water Website';
 
$headers .= 'From: Agnes Water Website <steve@agneswaters.com.au>' . "\r\n";
 
$headers .= 'MIME-Version: 1.0' . "\r\n";
 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 
mail($to, $subject, $msg, $headers);
 
header("Location:http://www.agneswater.net.au/agneswater_enquiries/success.php");
 
}
 
}else{
 
//echo 'dont be too smart <br> dont call it directly';
$msg='<style>
 
.stl td{
 
font-family:Arial, Helvetica, sans-serif;
 
font-size:12px;
 
background-color:#F4F4F4;
 
}
 
</style>
 
           <table width="703" border="0" align="center" cellpadding="3" cellspacing="2" class="stl">
 
  <tr>
 
    <td colspan="4" style="background-color:#999999;"><strong>Enquiry From Website </strong></td>
 
  </tr>
 
  <tr>
 
    <td width="132" >First Name </td>
 
    <td width="222" >' . $_POST['FName'] . '</td>
 
    <td width="118" >Last Name </td>
 
    <td width="197" >' . $_POST['LName'] . '</td>
 
  </tr>
 
  <tr>
 
    <td >Town</td>
 
    <td >' . $_POST['Town'] . '</td>
 
    <td >Country</td>
 
    <td >' . $_POST['Country'] . '</td>
 
  </tr>
 
  <tr>
 
    <td >Arriving Date </td>
 
    <td >' . date("D d, M Y",strtotime($ar)) . ' </td>
 
    <td >Departing</td>
 
    <td >' . date("D d, M Y",strtotime($dep))  . ' </td>
 
  </tr>
 
  <tr>
 
    <td >Number of Persons </td>
 
    <td >' . $_POST['NumPers'] . '</td>
 
    <td >Email</td>
 
    <td >' . $_POST['email'] . '</td>
 
  </tr>
 
  <tr>
 
    <td >Phone Number </td>
 
    <td >' . $_POST['Phone'] . '</td>
 
    <td >Mobile Number </td>
 
    <td >' . $_POST['MPhone'] . '</td>
 
  </tr>
 
  <tr>
 
    <td colspan="4" >Additional Information or Question </td>
 
  </tr>
 
  <tr>
 
    <td colspan="4" >' . $_POST['AddInf'] . '</td>
 
  </tr>
 
</table>
 
';
 
//$to = 'steve@agneswaters.com.au';
 
$to = 'danny@datamouse.biz';
 
$subject = 'Enquiry from Agnes Water Website';
 
$headers .= 'From: Agnes Water Website <steve@agneswaters.com.au>' . "\r\n";
 
$headers .= 'MIME-Version: 1.0' . "\r\n";
 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 
mail($to, $subject, $msg, $headers);
 
header("Location:http://www.agneswater.net.au/agneswater_enquiries/success.php");
 
}
 
?>

Open in new window

0
Comment
Question by:dannywareham
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 6

Expert Comment

by:youssefomar
ID: 22664364
I think the problem is you are creating the arrival and departure date like this:
$ar = $ArrMM  . "/" . $ArrDD . "/" . $ArrYY;
 
$dep = $DepMM . "/" . $DepDD  . "/" . $DepYY;
 
$ar =date('m/d/Y',strtotime($ar));
 
$dep =date('m/d/Y',strtotime($dep));

and all these values   $ArrMM , $ArrDD, $ArrYY; $DepMM,  $DepDD ,  $DepYY;
Don't have values

so $ar and $dep will be equal to "//" this is what causing the strtotime() function to give you 1969 date
0
 
LVL 26

Author Comment

by:dannywareham
ID: 22664685
Aren't these values passed from the javascript form?
They are the form values:


function testDate(theForm) {
  var now = new Date();
  var thisYear = now.getFullYear();
  var jan1 = Date.UTC(thisYear, 0, 1);
  now = Date.UTC(now.getFullYear(),now.getMonth(), now.getDate());
  var arrival = Date.UTC(theForm["ArrYY"].value, (parseInt(theForm["ArrMM"].value) - 1), theForm["ArrDD"].value);
  var departure = Date.UTC(theForm["DepYY"].value, (parseInt(theForm["DepMM"].value) - 1), theForm["DepDD"].value);
  if (arrival == jan1) {
    alert("Arrival date cannot be January 1st "+thisYear);
    theForm["ArrDD"].focus();
    return false;
  }
  if (arrival >= departure) {
    alert("Departure date must be after arrival date");
    theForm["DepDD"].focus();
    return false;
  }
  if (departure < now) {
    alert("Departure date must be in the future");
    theForm["DepDD"].focus();
    return false;
  }
  if (arrival < now) {
    alert("Arrival date must be in the future");
    theForm["ArrDD"].focus();
    return false;
  }
  return true;
}

Open in new window

0
 
LVL 6

Accepted Solution

by:
youssefomar earned 2000 total points
ID: 22664825
if these variable being passed from HTML then you need to use $_POST to read them :

try this

$ar = $_POST['ArrMM']  . "/" . $_POST['ArrDD'] . "/" . $_POST['ArrYY'];
 
$dep = $_POST['DepMM'] . "/" . $_POST['DepDD']  . "/" . $_POST['DepYY'];

Open in new window

0
 
LVL 26

Author Closing Comment

by:dannywareham
ID: 31504029
Muchas gracias.
Worked like a  charm :)
0

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question