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! Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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: #"); ?> Quote Link to comment 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! Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Nexy Posted June 6, 2008 Author Share Posted June 6, 2008 Ok, thank you once again! Quote Link to comment 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.