View Full Version : Question about mysql_query format

06-05-2005, 08:53 PM
Im reading a PHP book to learn more functions and crap, and they do thier querys like so

mysql_query("SELECT * FROM user WHERE username='{$_POST['username']}' and so on and so forth

my question is what are the { and } for cant you just have $_POST['username'] in there without those?

06-05-2005, 10:04 PM
The {}'s are used where the variable is an array element. If it's a string then you don't need the braces but if it's an array you need them for PHP to know that it needs to parse the array.

The alternative would be to close the quotes, concatenate the array element then open the quotes again, like so:

mysql_query("SELECT * FROM user WHERE username='" . $_POST['username'] . "'

I guess it's just personal preference which method you use, although I prefer the latter.