Jump to content

PHp & MYSQL Date Confusion


JackWetson

Recommended Posts

Hi All,

 

Im using the below code to create basically a key depending on which product is bought, however the expiry keeps going back to the year 1967 or something like that. I cannot see anything wrong with my code. Can anyone advise where I am going wrong?

 

<?php
require_once('./class/paypal.php'); //when needed
require_once('./class/httprequest.php'); //when needed

//Use this form for production server 
//$r = new PayPal(true);

//Use this form for sandbox tests
$r = new PayPal();

$final = $r->doPayment();

if ($final['ACK'] == 'Success') {

$key = sha1($_COOKIE['myusername']+microtime(true).mt_rand(10000,90000));
$user = $_COOKIE['myusername'];
$host = "tXYZ"; // Host name
$username = "XXXXX"; // Mysql username
$password = "@sdasdasdasdU)J&4z[X!IT"; // Mysql password
$db_name = "toasdasdas"; // Database name
$tbl_name = "keys"; // Table name
$product = $_COOKIE['product'];
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password") or die("cannot connect");
mysql_select_db("$db_name") or die("cannot select DB");
$today = date("YYYY-MM-DD");
switch ($product)
{
case "Torn Buddy - 1 Year":
{

$timestamp = mktime(0,0,0,date("m"),date("d"),date("Y")+1);
	$expiry = date("Y-m-d",$timestamp);


	break;
    }
case "Torn Buddy - 6 Months":
{
$timestamp =mktime(0,0,0,date("m")+6,date("d"),date("Y"));
	$expiry = date("Y-m-d",$timestamp);
	break;
    }
case "Torn Buddy - 3 Months":
{
$timestamp =mktime(0,0,0,date("m")+3,date("d"),date("Y"));
	$expiry = date("Y-m-d",$timestamp);
	break;
    }
case "Torn Buddy - 1 Month":
{
$timestamp =mktime(0,0,0,date("m")+1,date("d"),date("Y"));
	$expiry = date("Y-m-d",$timestamp);
	break;
    }
case "Torn Buddy - 3 Day":
{
	$timestamp =mktime(0,0,0,date("m"),date("d")+3,date("Y"));
	$expiry = date("Y-m-d",$timestamp);

	break;
}
}


$expiry = date("YYYY-MM-DD", $timestamp);
$sql = "INSERT INTO `keys` (`User` ,`Key` ,`Type` ,`Start` ,`End` ,`InUse`) VALUES ('$user', '$key', '$product', '$today', '$expiry', '0')";

	mysql_query($sql);
}

?>
.... more code

Link to comment
Share on other sites

nothing stands out at first glance expect you dont have default: in your switch at the bottom..

 

Edit: to answer your last question.. I am looking into it further, maybe nightsly will see something as he is in here as well..

Link to comment
Share on other sites

$expiry = date("YYYY-MM-DD", $timestamp);

 

This stands out for me.  A variable is only as good as it's last defined value.  Here you have it defined as an invalid string.  If you echo'd the expiry variable, you would find it prints out.

 

2011201120112011-0808-1212

 

Instead of the expected.

 

2011-08-12.

 

You did have it right in earlier codings.

$expiry = date('Y-m-d',$timestamp);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.