View Full Version : What is wrong with this update query?
SlowRoasted
March 26th, 2006, 10:59 AM
I get the echo "error" else statement, meaning the query didn't run. What's up? I've checked spelling for the fields in the database. I've made sure all variables are set correctly.:a:
if($_GET['page'] == 'contact'){
$id = $_GET['id'];
$pe = escape_data($_GET['pubemail']);
$co = escape_data($_GET['company']);
$ut = escape_data($_GET['usertitle']);
$a1 = escape_data($_GET['address1']);
$a2 = escape_data($_GET['address2']);
$ci = escape_data($_GET['city']);
$st = escape_data($_GET['state']);
$zi = escape_data($_GET['zipcode']);
echo $id." ".$pe." ".$co." ".$ut." ".$a1." ".$a2." ".$ci." ".$st." ".$zi." ";
$queryc = "UPDATE members SET pubemail='$pe', company='$co', usertitle='$ut', address1='$a1', address2='$a2', city='$ci', state='$st', zip='$zi' WHERE id=$id";
$resultc = @mysql_query($queryc);
if($resultc){echo "Contact Information Updated";}else{echo"error";}
}
melvijin
March 26th, 2006, 11:30 AM
dud check this out!!!
$queryc = "UPDATE members SET pubemail='$pe',
company='$co', usertitle='$ut', address1='$a1',
address2='$a2', city='$ci', state='$st', zip='$zi'
WHERE id=$id";
the code WHERE id=$id
make that WHERE id='$id'
$queryc = "UPDATE members SET pubemail='$pe',
company='$co', usertitle='$ut', address1='$a1',
address2='$a2', city='$ci', state='$st', zip='$zi'
WHERE id='$id'";
rok on!!! :)
SlowRoasted
March 26th, 2006, 01:20 PM
Yeah I've done that and it still doesn't work.
Ankou
March 26th, 2006, 01:26 PM
the code WHERE id=$id
make that WHERE id='$id'
Actually if "id" is an integer (or numerical value), like I'm guessing it is, then it shouldn't have the quotes around it.
I've had issues like this before where I've checked everything and still get an error. The solution's been different most times -- mainly because I messed something up. :p
It's hard to know what your DB set looks like. By just looking at the code, I need to ask. For the zip code (zip in the DB), is that an integer or are you allowing for non-numeric characters? If the zip is set up as an integer (or numerical value) then you wouldn't need the quotes around the $zi.
If that doesn't work, it would be helpful to see how you have your database set up.
Seb Hughes
March 26th, 2006, 01:31 PM
Are you connecting to the database?
Maybe:
echo $id." ".$pe." ".$co." ".$ut." ".$a1." ".$a2." ".$ci." ".$st." ".$zi." ";
Should be
echo "".$id." ".$pe." ".$co." ".$ut." ".$a1." ".$a2." ".$ci." ".$st." ".$zi." ";
else it beats the **** out of me.
SlowRoasted
March 26th, 2006, 01:56 PM
That echo is just to check if the variable are set okay.
Here are my fields, all are varchar accept id=int, status=char(3), subscription=char(3)
id
firstname
lastname
email
username
password
access
pubemail
company
address1
address2
city
state
zip
service
zone
status
subscription
title
Ankou
March 26th, 2006, 06:29 PM
That echo is just to check if the variable are set okay.
Here are my fields, all are varchar accept id=int, status=char(3), subscription=char(3)
id
firstname
lastname
email
username
password
access
pubemail
company
address1
address2
city
state
zip
service
zone
status
subscription
title
$queryc = "UPDATE members SET pubemail='$pe', company='$co', usertitle='$ut', address1='$a1', address2='$a2', city='$ci', state='$st', zip='$zi' WHERE id=$id";
usertitle='$ut' ... I don't see a "usertitle" in your database. There's the problem: usertitle should be username
I setup a database and ran a test, orginally it failed to make the updates. I then changed usertitle='$ut' to be username='$ut' for your query and then it worked fine.
melvijin
March 26th, 2006, 06:55 PM
usertitle should be username
yeah!!!
SlowRoasted
March 27th, 2006, 08:53 AM
Thanks Ankou that worked. Thanks for going through all the trouble to figure out my stupid mistake:P
Ankou
March 27th, 2006, 03:03 PM
Thanks Ankou that worked. Thanks for going through all the trouble to figure out my stupid mistake:P
No prob SlowRoasted, glad I could help. And hey, I've made that same mistake a few times in the past myself so I know how it goes!
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.