Jump to content

[SOLVED] Syntax Problem?


Nexy

Recommended Posts

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

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: #");
?>

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.