简体   繁体   中英

sql query was working and now not? insert user ip address into table?

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')";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM