mySQL misery.

C++, C#, Java, PHP, ect...
Post Reply
Age of Fable
Posts: 54
Joined: Fri Feb 19, 2010 6:37 am

mySQL misery.

Post 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)
Easy to play - hard to survive. http://www.ageoffable.net
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: mySQL misery.

Post 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?
Age of Fable
Posts: 54
Joined: Fri Feb 19, 2010 6:37 am

Re: mySQL misery.

Post 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.
Easy to play - hard to survive. http://www.ageoffable.net
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: mySQL misery.

Post by hallsofvallhalla »

Code: Select all

$qry="UPDATE current SET key='$key' WHERE email='$emailadd'";
Age of Fable
Posts: 54
Joined: Fri Feb 19, 2010 6:37 am

Re: mySQL misery.

Post 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'
Easy to play - hard to survive. http://www.ageoffable.net
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: mySQL misery.

Post 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';
Fighting for peace is declaring war on war. If you want peace be peaceful.
Age of Fable
Posts: 54
Joined: Fri Feb 19, 2010 6:37 am

Re: mySQL misery.

Post 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'
Easy to play - hard to survive. http://www.ageoffable.net
Falken
Posts: 438
Joined: Fri May 08, 2009 8:03 pm

Re: mySQL misery.

Post by Falken »

You want the ` quotes, not the ' ones, there is a difference between them :P
--- Game Database ---
For all your game information needs!
Visit us at: http://www.gamedatabase.eu today!
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: mySQL misery.

Post 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.
Age of Fable
Posts: 54
Joined: Fri Feb 19, 2010 6:37 am

Re: mySQL misery.

Post by Age of Fable »

Thanks, it's now working.
Easy to play - hard to survive. http://www.ageoffable.net
Post Reply

Return to “Coding”