Jump to content

PHP syntax


davidf85

Recommended Posts

In a piece of code like this:

mysql_query("INSERT into users VALUES ('".$_POST['username']."', '".$_POST['password']."')") or die(mysql_error());

 

What is the difference between

('".$_POST['username'])."')

(".$_POST['username']).')

(.$_POST['username'].) and

($_POST['username'])  ??  Will all four of these work?

Does anyone know where in the PHP manual I can find explanation for these syntaxes?

Link to comment
Share on other sites

None of those would work. What's in your code is ".$_POST['username']." - double quotes either side as to break out of / re-open the string that is opened / closed with double quotes (mysql_query("INS...")). The dots are the 'concatenation' operator that joins strings (literal or within variables) together. The single quotes are part of the actual SQL.

 

Often people find it more readable to use curly braces to concatenate the strings:

 

'{$_POST['username']}'

 

Read the manual for more information. Also have a read up on how to prevent SQL injections.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.