Error with SQL Syntax

Hello,

What is the problem with this SQL syntax?

[php]mysql_query(“UPDATE counter SET unique=’$amount’, ip=’$ip_string’ WHERE id=‘1’;”)[/php]

Here is the error it generates:

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 'unique='1', ip='2.97.202.93|' WHERE id='1'' at line 1

Thanks

1 is an integer dont need to be enclosed in single quotation

Should be

[php]mysql_query(“UPDATE counter SET unique=’$amount’, ip=’$ip_string’ WHERE id=1;”)[/php]

Ok i changed it

But it is still giving me an 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 ‘unique=‘1’, ip=‘2.97.202.93|’ WHERE id=1’ at line 1

if vairbales like $amount contains numbers they dont need be enclosed in single quotation

Still getting errors:

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 ‘unique=1, ip=‘2.97.202.93|’ WHERE id=1’ at line 1

this is the rule in SQL.

you only enclose in single quotation when value is a string

here are some examples

WHERE users='peter'
WHERE ID=10

with variables:

$lastname = "obama";
WHERE lastname= '$lastname'
$ID=10;
WHERE id=$ID

all of the above are valid examples

show your query.

what you currently have.

mysql_query(“UPDATE counter SET unique=$amount, ip=’$ip_string’ WHERE id=1;”)

Is it the IP that’s messing up, it has numbers AND letters

yeah it’s the ip
so
$ip_string = 2.97.202.93| ?

what up the pipe sgn? ( | )

Its still giving me errors.

Its where it will explode the string into a array.

does it work if you remove the pipe and remove the single quotation?

OK removed the pipe.

mysql_query(“UPDATE counter SET unique=$amount, ip=$ip_string WHERE id=1;”)

Still getting 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 ‘unique=1, ip=2.97.202.93 WHERE id=1’ at line 1

found the mistake

try this query

mysql_query("UPDATE `counter` SET `unique`=$amount, ip='$ip_string' WHERE id=1;")

the mistake was unique is a SQL reserved word, to avoid the error i used the grave sign (`)

now you can use the pipe sign it will be okay

Woo!

Thanks for the help :smiley:

Glad that I could help

Sponsor our Newsletter | Privacy Policy | Terms of Service