Nexy Posted June 6, 2008 Share Posted June 6, 2008 Why Hello There! Does anyone see a problem with my syntax or any other problem? <?php $ip = mysql_real_escape_string(stripslashes($_SERVER['REMOTE_ADDR'])); setcookie("user", $user, time()+(60*60*24*365)); $cookies = "UPDATE users SET ip = '$ip' WHERE username = '".$_COOKIE['user']."'"; $cookieres = mysql_query($cookies) OR die(mysql_error()); header("location: #"); ?> It doesn't give me any error, when I check phpmyadmin, the ip is not inserted. Thank You to anyone who helps! Link to comment https://forums.phpfreaks.com/topic/109023-solved-syntax-problem/ Share on other sites More sharing options...
Darklink Posted June 6, 2008 Share Posted June 6, 2008 I'm not sure if UPDATE produces an error. If there are no rows to edit, it should just not update any rows. Check that the user cookie is actually set and see what value it is. Link to comment https://forums.phpfreaks.com/topic/109023-solved-syntax-problem/#findComment-559274 Share on other sites More sharing options...
Nexy Posted June 6, 2008 Author Share Posted June 6, 2008 The cookie's value is the username. I did echo and it echoed the username. So it is being set. Link to comment https://forums.phpfreaks.com/topic/109023-solved-syntax-problem/#findComment-559278 Share on other sites More sharing options...
LemonInflux Posted June 6, 2008 Share Posted June 6, 2008 For a start, probably doesn't do any harm, but why are you escaping the IP address? Also, as far as I recall, cookies don't work immediately, so just use the $user variable in your query, instead of the cookie (they'll be the same). So it looks like this: <?php $ip = mysql_real_escape_string(stripslashes($_SERVER['REMOTE_ADDR'])); setcookie("user", $user, time()+(60*60*24*365)); $cookies = "UPDATE `users` SET `ip` = '$ip' WHERE `username` = '$user'"; // $user variable used in the setting of the cookie. $cookieres = mysql_query($cookies) or die(mysql_error()); header("location: #"); ?> Link to comment https://forums.phpfreaks.com/topic/109023-solved-syntax-problem/#findComment-559280 Share on other sites More sharing options...
Nexy Posted June 6, 2008 Author Share Posted June 6, 2008 Well, I thought it wouldn't hurt to escape it. Does it cause any problems or just a waste of code? BTW, thank you, I put $user and it worked. Cheers! Link to comment https://forums.phpfreaks.com/topic/109023-solved-syntax-problem/#findComment-559283 Share on other sites More sharing options...
LemonInflux Posted June 6, 2008 Share Posted June 6, 2008 It's just numbers and full stops really, so you'd be quite safe without escaping OR stripping the slashes. Link to comment https://forums.phpfreaks.com/topic/109023-solved-syntax-problem/#findComment-559309 Share on other sites More sharing options...
Nexy Posted June 6, 2008 Author Share Posted June 6, 2008 Ok, thank you once again! Link to comment https://forums.phpfreaks.com/topic/109023-solved-syntax-problem/#findComment-559361 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.