Page 1 of 1
Small SQL problem
Posted: Thu Aug 18, 2011 6:14 pm
by iKevz
Hey, could anybody tell me whats wrong with this sql? I know it's just a tiny error and i'm gunna kick myself after but i've wrote so much code today i just can't find it
Code: Select all
$result = ("UPDATE users SET 'about' = '$about', 'interested' = '$interested', 'relationship' = '$relationship', 'gender' = '$gender' WHERE username = '$user'");
Re: Small SQL problem
Posted: Thu Aug 18, 2011 8:21 pm
by twinedev
You have the fields surrounded by single quotes ( ' ) instead of backticks ( ` ):
Code: Select all
$result = ("UPDATE users SET `about` = '$about', `interested` = '$interested', `relationship` = '$relationship', `gender` = '$gender' WHERE `username` = '$user'");
Re: Small SQL problem
Posted: Fri Aug 19, 2011 5:13 am
by phphelpme
This is how I would normally code it:
Code: Select all
$result = "UPDATE users SET about='$about', interested='$interested', relationship='$relationship', gender='$gender' WHERE username='$user'";
Best wishes
Re: Small SQL problem
Posted: Fri Aug 19, 2011 5:36 am
by genix2011
Hi,
what twindev did is better, because it is the mysql standard and you won't get in trouble if you use reserved words as field names.
Greets.
Re: Small SQL problem
Posted: Fri Aug 19, 2011 1:25 pm
by phphelpme
That is a fair statement I agree but lets face it, you should not use reserved words anyway because they are reserved.
Best wishes
Re: Small SQL problem
Posted: Fri Aug 19, 2011 1:30 pm
by genix2011
Yeah you are right, but what if you wrote your query for lets say MySQL 4 and now tries to execute it in MySQL 5, now there could be new reserved words in MySQL 5 that were not in MySQL 4.
It just feels safer and better to use backticks

Re: Small SQL problem
Posted: Fri Aug 19, 2011 2:06 pm
by phphelpme
Yes, I do agree with you on that one and I can not say anything negative about your statements. It would be safer to use those back ticks but I would not understand anyone needing to revert back to 'v4' because as standard servers come with the latest version and as soon as another 'v' is available the hosting providers upgrade but always add some code to support backwards capability.
But in the safe run i suppose you might as well use them but to me on my personal servers and remote servers I would not use anything other than the latest version I suppose. lol
Best wishes