Jump to content

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
https://forums.phpfreaks.com/topic/225362-wont-set-cookie/
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
https://forums.phpfreaks.com/topic/225362-wont-set-cookie/#findComment-1163844
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
https://forums.phpfreaks.com/topic/225362-wont-set-cookie/#findComment-1163847
Share on other sites

You should format a date for display in your SELECT query, not when you INSERT it, that way you can use MySQL's native date and time functions if you need to compare it, add or subtract time values, use it in an ORDER BY, etc.

Link to comment
https://forums.phpfreaks.com/topic/225362-wont-set-cookie/#findComment-1163851
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
https://forums.phpfreaks.com/topic/225362-wont-set-cookie/#findComment-1163856
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
https://forums.phpfreaks.com/topic/225362-wont-set-cookie/#findComment-1163859
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
https://forums.phpfreaks.com/topic/225362-wont-set-cookie/#findComment-1164109
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.