[英]cannot compare ip address in wordpress php
我创建了一个自定义表来存储ip和post id
$wpdb->insert('wp_firstvisit',
array('IP' => $_SERVER['REMOTE_ADDR'],
'post_id'=>$post_id ),
array('%s','%d')
);
当我尝试使用
$ip = $_SERVER['REMOTE_ADDR'];
$result = $wpdb->get_row("SELECT * FROM wp_firstvisit WHERE post_id =$post_id AND ip=$ip");
我什么也没有
什么时候
AND ip=$ip
被删除我得到一行
那个时期,那行不通。 IP地址不是数字。 这是一个字符串。 你在做什么
SELECT ... ip = 127.0.0.1
由于这不是一个有效的数字,并且是一个未加引号的字符串,因此您将在sql级别收到语法错误:
mysql> select 'foo' = 127.0.0.1;
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near '.0.1' at line 1
^^^^^^
字符串必须用引号引起来:
SELECT ... ip = '127.0.0.1';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.