Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Date Variable is Changing to 31 Dec 1969

Posted on 2008-10-07
4
Medium Priority
?
493 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
  • 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

782 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