SQL查询工作,现在不行? 将用户IP地址插入表中?

My SQL query was working fine just 5 hours ago and now it's not? I have not touched a thing.

Can someone please help me get to the bottom of this, it should get the users ip address and store it in the table along with the current time and date, its not inserting anything, would appreciate some help.

Here is my table:

+-------------------------------------------------------------+
|session_id |    user_ip     |    session_start  | session_end|
|===========|================|===================|============|
|          1|  192.135.123.13|   23:02:20 10:23  | NULL       |
+-------------------------------------------------------------+

Here is my SQL:

// GET IP ADDRESS
 $sql = "INSERT INTO ptb_sessions (session_id, user_ip, session_start, session_end) VALUES (NULL, '" . $_SERVER['REMOTE_ADDR'] . "', now(), NULL);"; 
 mysql_query($sql, $connection); ?>  

Go step by step.

  1. Try inserting the simplest data with values sets to (1, '127.0.0.1', now(), now())
  2. If it is ok, try adding the $_SERVER['REMOTE_ADDR'] instead of 127.0.0.1

Be careful with case in tables and columns names.

If the 1 does not work in your PHP code, try to execute your SQL insert directly with a MySQL GUI (MySQL Workbench for example), an error should be raised.

If the insertion works fine with a MySQL GUI, then check your connection parameters in PHP.

add this $user_ip= $_SERVER['REMOTE_ADDR'];

should be like this

$sql = "INSERT INTO ptb_sessions (session_id, user_ip, session_start, session_end) VALUES ('$session_id', '$user_ip', '$session_start', '$session_end')";