JackWetson Posted August 12, 2011 Share Posted August 12, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/244638-php-mysql-date-confusion/ Share on other sites More sharing options...
AyKay47 Posted August 12, 2011 Share Posted August 12, 2011 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.. Quote Link to comment https://forums.phpfreaks.com/topic/244638-php-mysql-date-confusion/#findComment-1256546 Share on other sites More sharing options...
JackWetson Posted August 12, 2011 Author Share Posted August 12, 2011 I didn't bother with default as the user won't even get to this page if product isnt set, other than that you think it should work? Quote Link to comment https://forums.phpfreaks.com/topic/244638-php-mysql-date-confusion/#findComment-1256550 Share on other sites More sharing options...
jcbones Posted August 13, 2011 Share Posted August 13, 2011 $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); Quote Link to comment https://forums.phpfreaks.com/topic/244638-php-mysql-date-confusion/#findComment-1256677 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.