Jump to content


Photo

Problem with SQL query UPDATE


  • Please log in to reply
8 replies to this topic

#1 joecooper

joecooper
  • Members
  • PipPipPip
  • Advanced Member
  • 358 posts

Posted 11 March 2006 - 11:27 PM

<?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
Signature:
[/a]
[a href="http://www.planet-so...=1999&lngWId=8" target="_blank"]EzLogin 1.0[/a]
[a href="http://www.essexracers.com" target="_blank"]Essexracers.com[/a]
Msn Messenger: joe@joeyjoe.co.uk

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 11 March 2006 - 11:34 PM

sigh

I bet if you echo'd the mysql_error() you would get a clue what the problem is.
Legend has it that reading the manual never killed anyone.
My site

#3 joecooper

joecooper
  • Members
  • PipPipPip
  • Advanced Member
  • 358 posts

Posted 11 March 2006 - 11:43 PM

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?
Signature:
[/a]
[a href="http://www.planet-so...=1999&lngWId=8" target="_blank"]EzLogin 1.0[/a]
[a href="http://www.essexracers.com" target="_blank"]Essexracers.com[/a]
Msn Messenger: joe@joeyjoe.co.uk

#4 joecooper

joecooper
  • Members
  • PipPipPip
  • Advanced Member
  • 358 posts

Posted 11 March 2006 - 11:59 PM

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!
Signature:
[/a]
[a href="http://www.planet-so...=1999&lngWId=8" target="_blank"]EzLogin 1.0[/a]
[a href="http://www.essexracers.com" target="_blank"]Essexracers.com[/a]
Msn Messenger: joe@joeyjoe.co.uk

#5 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 12 March 2006 - 12:30 AM

Hint: Don't use reserved words for table names or field names.

key [a href=\"http://www.htmlite.com/mysql002a.php\" target=\"_blank\"]is in the list of reserved words[/a] <- good bookmark
Legend has it that reading the manual never killed anyone.
My site

#6 joecooper

joecooper
  • Members
  • PipPipPip
  • Advanced Member
  • 358 posts

Posted 12 March 2006 - 01:40 AM

argh! i really should use a prefix for all my scripts
Signature:
[/a]
[a href="http://www.planet-so...=1999&lngWId=8" target="_blank"]EzLogin 1.0[/a]
[a href="http://www.essexracers.com" target="_blank"]Essexracers.com[/a]
Msn Messenger: joe@joeyjoe.co.uk

#7 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 12 March 2006 - 10:15 AM

[!--quoteo(post=354059:date=Mar 12 2006, 01:40 AM:name=joecooper)--][div class=\'quotetop\']QUOTE(joecooper @ Mar 12 2006, 01:40 AM) View Post[/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

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

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/


#8 saiko

saiko
  • Members
  • PipPipPip
  • Advanced Member
  • 37 posts

Posted 12 March 2006 - 10:30 AM

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

#9 joecooper

joecooper
  • Members
  • PipPipPip
  • Advanced Member
  • 358 posts

Posted 12 March 2006 - 12:44 PM

Thannks all!, ive changed the feild name in the database in the end! thanks ever so much.
Signature:
[/a]
[a href="http://www.planet-so...=1999&lngWId=8" target="_blank"]EzLogin 1.0[/a]
[a href="http://www.essexracers.com" target="_blank"]Essexracers.com[/a]
Msn Messenger: joe@joeyjoe.co.uk




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users