Jump to content

Archived

This topic is now archived and is closed to further replies.

joecooper

Problem with SQL query UPDATE

Recommended Posts

<?php
session_start();
include("db.php");
echo "Your username:$username, Your key:$key";
mysql_query("UPDATE users SET active='yes' WHERE key='$key'");
?>

i have this code, the db.php file is fine, the $key and $username varibles come from the link, that allworks, but it doesnt want to update the feild "active". the keys match ect. im not sure what to try

Share this post


Link to post
Share on other sites
sigh

I bet if you echo'd the mysql_error() you would get a clue what the problem is.

Share this post


Link to post
Share on other sites
very true :)

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=''' at line 1

wtf does that mean?

Share this post


Link to post
Share on other sites
i have this code on another page, and it works fine:

mysql_query ("UPDATE 4x4page SET title='$title', info='$info', picture='$picture', price='$price' WHERE id='$id' ");

i cannot find anything wrong with it!

Share this post


Link to post
Share on other sites
Hint: Don't use reserved words for table names or field names.

[b]key[/b] [a href=\"http://www.htmlite.com/mysql002a.php\" target=\"_blank\"]is in the list of reserved words[/a] <- good bookmark

Share this post


Link to post
Share on other sites
[!--quoteo(post=354059:date=Mar 12 2006, 01:40 AM:name=joecooper)--][div class=\'quotetop\']QUOTE(joecooper @ Mar 12 2006, 01:40 AM) [snapback]354059[/snapback][/div][div class=\'quotemain\'][!--quotec--]
argh! i really should use a prefix for all my scripts
[/quote]

if you're going to use a reserved word.. you could encapsulate it like

[code]select * from users where [key] = '1'[/code]

Share this post


Link to post
Share on other sites
mysql_query("UPDATE users SET active='yes' WHERE key='$key'");

i suggest use `` located next to the number 1

mysql_query("UPDATE `users` SET `active`='yes' WHERE `key`='$key'");

a problem i had a while back :D

Share this post


Link to post
Share on other sites
Thannks all!, ive changed the feild name in the database in the end! thanks ever so much.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.