Question:
Mysql syntax error - ?
O Xabarin
2008-10-31 23:24:03 UTC
The error:
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 '.967.754)' at line 1 (I changed the IP numbers)

$ip = $_SERVER['REMOTE_ADDR'];
global $ip;
$id = $_GET['ID'];

$ip = mysql_real_escape_string($ip);
$ipcheck = mysql_query("SELECT * FROM votes WHERE word_id LIKE $id AND ip LIKE $ip") or die (mysql_error());
Three answers:
just "JR"
2008-11-01 01:35:17 UTC
Wrong usage of "LIKE". If you look for the same value, use "=".

If you look for an IP that contains part of the original IP, use "LIKE".

Don't use "LIKE" for a full IP!

ie: $Ip = "123.456.789.012"; // make sure it is a STRING!

-> LIKE will only find exactly that one

"Cut" the IP: $ipshort = "123.456.": now, "LIKE" will find these:

123.456.xxx.xxx, xxx.123.456.xxx, but not xxx.xxx.123.456.

Write your sql with the correct syntax:

$sql = "select * from `votes` where `word_id` like '%".$id."%' and `ip` like '%".$ipshort."%'";

$list = mysql_query($sql);

while ($lst = mysql_fetch_array($list))

{ do something }

mysql_free_result($list);



Pay attention to ` ' " !
prokosch
2016-10-06 14:22:11 UTC
Why the message id is null and that's normally happening key. normally happening key should not be null, that's used for indexing attempt working the question in my view first, in mysql command instant
andylah
2008-10-31 23:29:08 UTC
SELECT * FROM votes WHERE word_id LIKE '$id' AND ip LIKE '$ip' "







visit my blog about linux :



http://andylah.blospot.com


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...