Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7189367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:17:13+00:00 2026-05-28T19:17:13+00:00

For example, check this following query; $query = SELECT * FROM users WHERE user='{$_POST[‘username’]}’;

  • 0

For example, check this following query;

$query = "SELECT * FROM users WHERE user='{$_POST['username']}';  

What’s the use?

In string contexts, I do understand the problem it solves.
I can do stuff like
$animal = “cat”
echo “{$animal}s.” // outputs cats

but in the SQL I posted above, I just don’t get it.
Wouldn’t the following be equally good?

$query = "SELECT * FROM users WHERE user='$_POST['username']' AND password='$_POST['password']'";  

So, Where does using the { and } get handy? Appreciate any example in SQL context?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:17:14+00:00Added an answer on May 28, 2026 at 7:17 pm

    See http://www.php.net/manual/de/language.types.string.php#language.types.string.parsing for the double quote string syntax.

    The curly braces are for complex variable expressions. They are interpreted by PHP, not by the SQL interface.

    $query = "SELECT * FROM users WHERE user='$_POST['username']' AND password='$_POST['password']'";  
    

    The above will lead to an parsing error. Without curly braces you have to write:

    $query = "SELECT * FROM users WHERE user='$_POST[username]' AND password='$_POST[password]'";  
    

    Note the lack of key quotes. This only works for a simple array access, and for a simple object property expression. For anything more complex, use the curly braces.


    Now that you know that, do a pinky swear that you won’t ever do so. Because interpolating user input directly there is not a good idea. http://bobby-tables.com/

    Do yourself a favour and use PDO with prepared statements. So much easier.


    But to give an example for a more complex curly string syntax, this is what I’d do:

    $query = "SELECT * FROM users WHERE user={$_POST->id->sql['username']}";
    

    (Does some inline filtering and quoting. Just as example, does not work with default PHP setups.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

check this example: > a = matrix(1:9, nrow = 3, ncol = 3, dimnames
I have a loop created with each, check this example: $('.foo').each(function(i){ //do stuff });
Please check the following example: http://www.esaer.com.br/csstest/ If the vertical scrollbar doesn't appear, please resize
For example, if passed the following: a = [] How do I check to
I have the following SQL Query: select Subjects.S_ID as ID, Subjects.S_ParentID as ParentID, Subjects.S_Name
Following program i picked from the php site (http://php.net/manual/en/mysqli.real-escape-string.php) and ran on my system
Is anyone aware of a way to remove redundant variables from a query string.
I'm using the following query to get the id and the username of a
The following TSQL provides an example of how I might solve this problem with
Following on from this question I asked yesterday: Can I shorten this regular expression?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.