Jump to content

Won't set cookie


WatsonN

Recommended Posts

I have part of my script that I have used many times in many diffrent applications that works just fine.

But in this use it refuses to set the cookie or do anything besides the redirect for that matter.

// if login is ok then we add a cookie 
	$ip = $_SERVER['REMOTE_ADDR'];
$datem = date("j F Y, g:i a");
mysql_query("UPDATE YBK_Login SET date = '$datem' AND ip = '$ip' WHERE ID = '{{$info['ID']}'")or die(mysql_error()); 

	 $_POST['username'] = stripslashes($_POST['username']); 
	 $hour = time() + 3600; 
setcookie('ID_WatsonN', $_POST['username'], 0); 
setcookie('Key_WatsonN', $_POST['pass'], 0);
setcookie('UID_WatsonN', $info['ID'], 0);	
setcookie('LOGIN', $info['ID'], time()+3);	
//then redirect them to the members area 
  Header("Location: dashboard.php"); 

Link to comment
Share on other sites

It looks like you have an extra curly brace prior to $info['ID'] in the query string also, so it probably isn't related to the date formatting (which was my initial thought). But may I ask why you'd store a timestamp in a VARCHAR field rather in a DATETIME field?

Link to comment
Share on other sites

@PFMaBiSmAd That would make sense wouldn't it.

	mysql_query("UPDATE YBK_Login SET date = '$datem', ip = '$ip' WHERE ID = '{$info['ID']}'")or die(mysql_error()); 

 

@Pikachu2000 I used VARCHAR instead because i wanted to format the date a spesific way and not the way mysql wanted it.

But both would work just as well.

 

Fixed

 // if login is ok then we add a cookie 
	$ip = $_SERVER['REMOTE_ADDR'];
$datem = date("j F Y, g:i a");
mysql_query("UPDATE YBK_Login SET date = '$datem', ip = '$ip' WHERE ID = '{$info['ID']}'")or die(mysql_error()); 

	 $_POST['username'] = stripslashes($_POST['username']); 
	 $hour = time() + 3600; 
setcookie('ID_WatsonN', $_POST['username'], 0); 
setcookie('Key_WatsonN', $_POST['pass'], 0);
setcookie('UID_WatsonN', $info['ID'], 0);	
setcookie('LOGIN', $info['ID'], time()+3);	
//then redirect them to the members area 
  Header("Location: dashboard.php"); 

Link to comment
Share on other sites

To insert a current timestamp into a DATETIME field you'd simply use NOW() as the value

INSERT INTO `table` (`date_time_field`) VALUES ( NOW() )

 

Then when retrieving the data, you'd use DATE_FORMAT() with an alias. The formatted string is then available in the array index of the alias; in this case it would be $array['stamp'] since the alias is `stamp`

SELECT DATE_FORMAT(`date_time_field`, '%e %M %Y, %l:%i %p) AS `stamp`

Link to comment
Share on other sites

I got the insert to work right, but how would I format the return?

$datetime = mysql_query("SELECT DATE_FORMAT(`date`, '%e %M %Y, %l:%i %p') AS `stamp` FROM YBK_Login")or die(mysql_error());
while($datetimecheck = mysql_fetch_assoc($datetime)) {
$date = $datetimecheck['stamp'];
}

Gives no errors but will not echo out anything.

Link to comment
Share on other sites

That would be a problem. I thought it would work a different way and tried to just put it into a variable.

I just put it inside where I wanted it to echo out.

$datetime = mysql_query("SELECT DATE_FORMAT(`date`, '%M %e %Y, %l:%i %p') AS `stamp` FROM YBK_Login WHERE `id` = '$CUR_USER_ID'")or die(mysql_error());

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.