Re: PHP Syntax Question



Thomas Mlynarczyk wrote:
Onideus Mad Hatter schrieb:

<removed irrelevant newsgroups>

$username = 'Onideus Mad Hatter';
"SELECT `name` FROM `user_data` WHERE `name` = '$username'"
... becomes
"SELECT `name` FROM `user_data` WHERE `name` = 'Onideus Mad Hatter'"

"SELECT name FROM user_data WHERE name = $username"
... becomes
"SELECT name FROM user_data WHERE name = Onideus Mad Hatter"
And that's just wrong in SQL. Leaving out the backticks is okay here,
but strings must be quoted. If you saw it like this in a tutorial, then
the tutorial is wrong.

It can be that the example in the tutorial was

"SELECT name FROM user_data WHERE user_id = $userid"

This completely valid way, if the column is of types like int and float.

The backticks are really useful if the columns or table names are the same as
reserved words in SQL, like key, order and so on.

--

//Aho
.