Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2004
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question about mysql_query format

    Im reading a PHP book to learn more functions and crap, and they do thier querys like so

    PHP Code:
    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?

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    PHP Code:
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •