WatsonN Posted January 23, 2011 Share Posted January 23, 2011 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"); Quote Link to comment https://forums.phpfreaks.com/topic/225362-wont-set-cookie/ Share on other sites More sharing options...
ManiacDan Posted January 23, 2011 Share Posted January 23, 2011 What debug steps have you tried? What's in POST? Are you sure the domain is right? //etc. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/225362-wont-set-cookie/#findComment-1163827 Share on other sites More sharing options...
WatsonN Posted January 23, 2011 Author Share Posted January 23, 2011 Almost Solved. I had spaces in my folder name. Took those out and fixed the cookie problem. Still wont update mysql. It has no errors, though. Quote Link to comment https://forums.phpfreaks.com/topic/225362-wont-set-cookie/#findComment-1163832 Share on other sites More sharing options...
WatsonN Posted January 23, 2011 Author Share Posted January 23, 2011 POST had sanitized login in details like username and password Quote Link to comment https://forums.phpfreaks.com/topic/225362-wont-set-cookie/#findComment-1163834 Share on other sites More sharing options...
Pikachu2000 Posted January 23, 2011 Share Posted January 23, 2011 What is the data type for your date field in the database? Quote Link to comment https://forums.phpfreaks.com/topic/225362-wont-set-cookie/#findComment-1163835 Share on other sites More sharing options...
WatsonN Posted January 23, 2011 Author Share Posted January 23, 2011 The date field is varchar limited to 30 Quote Link to comment https://forums.phpfreaks.com/topic/225362-wont-set-cookie/#findComment-1163839 Share on other sites More sharing options...
PFMaBiSmAd Posted January 23, 2011 Share Posted January 23, 2011 date = '$datem' AND ip = '$ip' AND is a logical operator, not a list separator. Quote Link to comment https://forums.phpfreaks.com/topic/225362-wont-set-cookie/#findComment-1163841 Share on other sites More sharing options...
Pikachu2000 Posted January 23, 2011 Share Posted January 23, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/225362-wont-set-cookie/#findComment-1163844 Share on other sites More sharing options...
WatsonN Posted January 23, 2011 Author Share Posted January 23, 2011 @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"); Quote Link to comment https://forums.phpfreaks.com/topic/225362-wont-set-cookie/#findComment-1163847 Share on other sites More sharing options...
Pikachu2000 Posted January 23, 2011 Share Posted January 23, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/225362-wont-set-cookie/#findComment-1163851 Share on other sites More sharing options...
WatsonN Posted January 23, 2011 Author Share Posted January 23, 2011 @Pikachu2000 What query should be written to do it that way? Quote Link to comment https://forums.phpfreaks.com/topic/225362-wont-set-cookie/#findComment-1163852 Share on other sites More sharing options...
Pikachu2000 Posted January 23, 2011 Share Posted January 23, 2011 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` Quote Link to comment https://forums.phpfreaks.com/topic/225362-wont-set-cookie/#findComment-1163856 Share on other sites More sharing options...
WatsonN Posted January 23, 2011 Author Share Posted January 23, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/225362-wont-set-cookie/#findComment-1163859 Share on other sites More sharing options...
Pikachu2000 Posted January 23, 2011 Share Posted January 23, 2011 There's no echo in that code chunk . . . Quote Link to comment https://forums.phpfreaks.com/topic/225362-wont-set-cookie/#findComment-1163992 Share on other sites More sharing options...
WatsonN Posted January 23, 2011 Author Share Posted January 23, 2011 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()); Quote Link to comment https://forums.phpfreaks.com/topic/225362-wont-set-cookie/#findComment-1164109 Share on other sites More sharing options...
WatsonN Posted January 24, 2011 Author Share Posted January 24, 2011 @Pikachu2000 Using the code you provided, How would I add an hour to the current time? My server is in a diffrent time zone and is an hour behind me. Quote Link to comment https://forums.phpfreaks.com/topic/225362-wont-set-cookie/#findComment-1164267 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.