Jump to content

Concerning periods before and after variables...


shoopaie

Recommended Posts

Hello everyone,

I have been learning about the "mysql_query" business, and from a file i downloaded to reference, I see that the developer has placed periods before and after his/her variables inside the INSERT INTO statement. Any reason why? And, is that required??? Thank you!

 

 

here is what the file had:

 

mysql_query("INSERT INTO `people` SET `username` = '".$username."',

`password` = '".$password."', `email` = '".$email."', `fullname` = '".$fullname."'");

Link to comment
Share on other sites

In this case, I don't think it's absolutely necessary. The periods just indicate string concatination -- strings combined with variables:

 

$string = "text here..." . $variable;

 

PHP will interpret variables within double quoted strings, so this isn't really necessary. If Within single quoted strings, the "$variable" will be interpreted as text, not a variable.

 

For example:

 

$variable = "test";
echo 'variable equals: $variable'; // will display "variable equals: $variable"

whereas

$variable = "test";
echo "variable equals: $variable"; // will display "variable equals: test"

In this particular case, I believe the sql query could also be written like this, without the periods:

 

mysql_query("INSERT INTO `people` SET `username` = '$username',
`password` = '$password', `email` = '$email', `fullname` = '$fullname'"); 

Link to comment
Share on other sites

Thank you kindly for the answer. I had a slight idea of the period being concatenation, but couldn't quite figure out what was being "concatenated" since one variable was being added to one field while the next was being added to an entirely different field. Strange I thought. I'll just chalk it up to not being needed, so i most likely won't ever use it.

 

Thanks again!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...