Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
hicuxunicorniobestbuildpc
The Mouse Is Extension Of Arm



Joined: Aug 13, 2009
Posts: 1122

PostPosted: Sun Oct 27, 2013 3:58 am Reply with quote

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
 
View user's profile Send private message
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Sun Oct 27, 2013 8:41 am Reply with quote

Any reference to a table or column must be "wrapped" in the backtics, so your second example is the correct one.

_________________
Where Do YOU Stand?
HTML Newsletter::ShortLinks::Mailer::Downloads and more... 
View user's profile Send private message Visit poster's website
hicuxunicorniobestbuildpc







PostPosted: Sun Oct 27, 2013 9:25 am Reply with quote

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
Regular



Joined: Aug 03, 2012
Posts: 56
Location: Rome Italy

PostPosted: Sun Oct 27, 2013 9:40 am Reply with quote

For me the right is
Code:
$db->sql_query("UPDATE ".$user_prefix."_users SET points=points+'$points' WHERE username='$username'");
 
View user's profile Send private message Send e-mail Visit poster's website
hicuxunicorniobestbuildpc







PostPosted: Sun Oct 27, 2013 9:54 am Reply with quote

misterstereus: Yours is good as well but we are talking about backsticks here with single quotes.
 
montego







PostPosted: Mon Oct 28, 2013 5:21 am Reply with quote

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







PostPosted: Mon Oct 28, 2013 7:00 am Reply with quote

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







PostPosted: Mon Oct 28, 2013 7:05 am Reply with quote

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







PostPosted: Mon Oct 28, 2013 7:11 am Reply with quote

Wow!!!. That's why I was getting a warning error in my log. Hmmm. Interesting!!! I think I am getting addictive to php.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©