Author |
Message |
hicuxunicorniobestbuildpc
The Mouse Is Extension Of Arm

Joined: Aug 13, 2009
Posts: 1123
|
Posted:
Sun Oct 27, 2013 3:58 am |
|
Guys!
I wonder how we can use backsticks in this line.
Code:$db->sql_query('UPDATE ' . $user_prefix.'_users SET points=points+' . $points . ' WHERE username=\'' . $username . '\'');
|
my convertion was this
Code:$db->sql_query('UPDATE `' . $user_prefix . '_users` SET `points` = points+' . $points . ' WHERE `username` = \'' . $username . '\'');
|
Is this correct above. Where I don't understand is on this line:
Code:`points` = points+' . $points .
|
or
Code:SET `points` = `points` + ' . $points . ' WHERE
|
|
|
|
|
 |
montego
Site Admin

Joined: Aug 29, 2004
Posts: 9457
Location: Arizona
|
Posted:
Sun Oct 27, 2013 8:41 am |
|
Any reference to a table or column must be "wrapped" in the backtics, so your second example is the correct one. |
_________________ Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! |
|
|
 |
hicuxunicorniobestbuildpc

|
Posted:
Sun Oct 27, 2013 9:25 am |
|
so you mean this one is the correct one?
Code:$db->sql_query('UPDATE `' . $user_prefix . '_users` SET `points` = points+' . $points . ' WHERE `username` = \'' . $username . '\'');
|
|
|
|
|
 |
misterstereus
Regular


Joined: Aug 03, 2012
Posts: 61
Location: Rome Italy
|
Posted:
Sun Oct 27, 2013 9:40 am |
|
For me the right is
Code:$db->sql_query("UPDATE ".$user_prefix."_users SET points=points+'$points' WHERE username='$username'");
|
|
|
|
|
 |
hicuxunicorniobestbuildpc

|
Posted:
Sun Oct 27, 2013 9:54 am |
|
misterstereus: Yours is good as well but we are talking about backsticks here with single quotes. |
|
|
|
 |
montego

|
Posted:
Mon Oct 28, 2013 5:21 am |
|
hicuxunicorniobestbuildpc, no, this is the example I was meaning:
Code:
SET `points` = `points` + ' . $points . ' WHERE
|
Every use of a table and column name must get the back tics.
Keep in mind, all of this will work with or without back tics. But, since you're wanting to put them in, would be best to be consistent by putting them everywhere (which I am sure is what you intended). |
|
|
|
 |
hicuxunicorniobestbuildpc

|
Posted:
Mon Oct 28, 2013 7:00 am |
|
Yes, that is my idea to make back tics everywhere. Thanks Montego for this clarification. Now I undertand when I see a column name with a symbol I must separate it. Very good example.
Montego: In admin.php we have a line like this
Code:$sql = 'SELECT `user_regdate`, COUNT(user_regdate) FROM `' . $user_prefix . '_users` WHERE `user_regdate` IN(\'' . $Today . '\', \'' . $Yesterday . '\') GROUP BY `user_regdate` LIMIT 0,2';
|
What happens when you find a column name inside parenthises. Can I use back ticks as well?
Code:$sql = 'SELECT `user_regdate`, COUNT(`user_regdate`) FROM `' . $user_prefix . '_users` WHERE `user_regdate` IN(\'' . $Today . '\', \'' . $Yesterday . '\') GROUP BY `user_regdate` LIMIT 0,2';
|
|
|
|
|
 |
montego

|
Posted:
Mon Oct 28, 2013 7:05 am |
|
hicuxunicorniobestbuildpc wrote: | What happens when you find a column name inside parenthises. Can I use back ticks as well? |
Yes, ALL uses of a table name and column name can get back ticks. |
|
|
|
 |
hicuxunicorniobestbuildpc

|
Posted:
Mon Oct 28, 2013 7:11 am |
|
Wow!!!. That's why I was getting a warning error in my log. Hmmm. Interesting!!! I think I am getting addictive to php. |
|
|
|
 |
|