I have the following table in the database:
id, username, email, old_ip, current_ip
Everytime the user logs in, I want their current ip to be stored in current_ip. But before that I want to save their old_ip (from last login) so I thought I could move what is in current_ip to old_ip before copying the new data to current_ip.
I wrote this script when logging in:
........
$sql = mysql_query("SELECT * FROM members WHERE email='$email' AND password='$password'");
$login_check = mysql_num_rows($sql);
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
// Get member ID into a session variable
$id = $row["id"];
session_register('id');
$_SESSION['id'] = $id;
// Get member username into a session variable
$username = $row["username"];
session_register('username');
$_SESSION['username'] = $username;
// IP getting
$old_ip = mysql_query("SELECT current_ip FROM members WHERE id='$id'");
$result_old_ip = $old_ip;
$sql_setoldip = mysql_query("UPDATE members SET old_ip='".$result_old_ip."' WHERE id='$id'");
$getip = getenv("REMOTE_ADDR");
$current_ip = $getip;
// Update ip in database
mysql_query("UPDATE members SET current_ip='".$current_ip."' WHERE id='$id'");
}
The result I get in the old_ip feild is “Resource id #7” Any help please ?
mysql_query()statement returns a resource pointer to the result set, not the data itself. You’ll need to usemysql_fetch_array()in order to retrieve the actual data in the table.like this:
this will solve your problem.
Hope this helps.