简体   繁体   English

SQL查询工作,现在不行吗? 插入用户的IP地址到表?

[英]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? 我的SQL查询仅在5个小时前运行良好,现在不是吗? 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. 有人可以帮我解决这个问题,它应该获取用户的ip地址并将其与当前时间和日期一起存储在表中,而不插入任何内容,将对您有所帮助。

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: 这是我的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()) 尝试插入值设置为(1, '127.0.0.1', now(), now())的最简单数据
  2. If it is ok, try adding the $_SERVER['REMOTE_ADDR'] instead of 127.0.0.1 如果可以,请尝试添加$_SERVER['REMOTE_ADDR']而不是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. 如果1在您的PHP代码中不起作用,请尝试直接使用MySQL GUI(例如MySQL Workbench)执行SQL插入,应引发错误。

If the insertion works fine with a MySQL GUI, then check your connection parameters in PHP. 如果插入可以在MySQL GUI上正常进行,请检查PHP中的连接参数。

add this $user_ip= $_SERVER['REMOTE_ADDR']; 添加此$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')";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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