Page 1 of 1

mySQL misery.

Posted: Sun May 02, 2010 10:18 am
by Age of Fable
I can't see the syntax error in this, but apparently there is one. Can anyone help?

UPDATE current SET key='yqsfod' WHERE email='news@apolitical.info'

(I've checked that current is a database, with a field email, and one of those fields has the value news@apolitical.info)

Re: mySQL misery.

Posted: Sun May 02, 2010 1:49 pm
by hallsofvallhalla
there is a field call key?

and when you say a database named current, you mean a table named current right?

what is the exact error and can we see more of the code?

Re: mySQL misery.

Posted: Sun May 02, 2010 2:08 pm
by Age of Fable
Yes, 'current' is a table.

Code: Select all

            $ok=1;
            $key="";
            for ($z=1;$z<=6;$z++) {
                $key=$key.chr(rand(97,122));
            }
            $qry="UPDATE current SET key='".$key."' WHERE email='".$emailadd."'";
            $result=mysql_query($qry,$link);

if (!$result) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= '<br>Whole query: ' . $qry;
    die($message);
}
This is the output:

Invalid query: 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 'key='tsosit' WHERE email='news@apolitical.info'' at line 1
Whole query: UPDATE current SET key='tsosit' WHERE email='news@apolitical.info'

I've checked $link, and it's the same as it is on other pages which work.

Re: mySQL misery.

Posted: Sun May 02, 2010 2:35 pm
by hallsofvallhalla

Code: Select all

$qry="UPDATE current SET key='$key' WHERE email='$emailadd'";

Re: mySQL misery.

Posted: Sun May 02, 2010 7:56 pm
by Age of Fable
That had the same output:

Invalid query: 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 'key='dozxop' WHERE email='news@apolitical.info'' at line 1
Whole query: UPDATE current SET key='dozxop' WHERE email='news@apolitical.info'

Re: mySQL misery.

Posted: Sun May 02, 2010 8:37 pm
by Chris
'key' is a reserved word in SQL, you will need to either call it a different field name or use proper quotation:

Code: Select all

UPDATE `current` SET `key`='$key' WHERE `email`='$emailadd';

Re: mySQL misery.

Posted: Sun May 02, 2010 8:58 pm
by Age of Fable
I added quotes to 'key', but that didn't change the result.

Invalid query: 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 ''key'='cjgzeq' WHERE email='news@apolitical.info'' at line 1
Whole query: UPDATE current SET 'key'='cjgzeq' WHERE email='news@apolitical.info'

Re: mySQL misery.

Posted: Sun May 02, 2010 10:05 pm
by Falken
You want the ` quotes, not the ' ones, there is a difference between them :P

Re: mySQL misery.

Posted: Mon May 03, 2010 12:34 am
by hallsofvallhalla
ah man I cant believe i missed that! yeah do not use key at all. I have had the same problem with other key words. Change the word key to something else.

Re: mySQL misery.

Posted: Mon May 03, 2010 4:42 am
by Age of Fable
Thanks, it's now working.