Click here to Skip to main content
15,905,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
On the log in page i want the user to log in and record their ip address in the 'last_login' column of my database. I can get the users IP address and echo it but i can't get it to UPDATE or even INSERT INTO the database. This is what i tried :
PHP
<?php
$con=mysql_connect("host","username","password","database");

if (mysql_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysql_connect_error();
  }
$username = $_POST['username'];;
$ip = $_SERVER['REMOTE_ADDR'];
mysql_query($con,"UPDATE users SET last_login='$ip' WHERE username='$username'");
?>
Posted
Comments
Er. Tushar Srivastava 16-Dec-13 12:37pm    
My Friend, I have a question.... Can you tell me the data type of the last_login column in your database in table users? I am damn sure that the problem is with the data type... Try to change the data type to VARCHAR(100) this will probably solve the issue...

I think you are wrong at the order of parameters while calling the mysql_query function. The correct call is described at http://www.w3schools.com/php/func_mysql_query.asp[^]
 
Share this answer
 
Tried this but it didn't work either... :
PHP
$con = mysql_connect("p-roject.com.mysql","p_roject_com","qhbJ5XZm","p_roject_com");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
$username = $_POST['username'];
$ip = $_SERVER['REMOTE_ADDR'];
$sql = "UPDATE users SET last_login='$ip' WHERE username='$username'";
mysql_query($sql,$con);
?>

last_login remains unchanged
 
Share this answer
 
Comments
CHill60 10-Dec-13 16:22pm    
Don't post comments as solutions - if you do this before someone offers a solution your question will drop out of the list of unanswered questions and fewer people will view it. Use the Improve question link next to your original question to add further details then delete this (non)solution
Member 10421693 10-Dec-13 16:52pm    
Dammit i knew i did something wrong -.- i meant to reply to thanh_bkhn...
CHill60 10-Dec-13 17:04pm    
You're not the only one so don't worry :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900