shoopaie Posted February 20, 2011 Report Share Posted February 20, 2011 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."'"); Quote Link to comment Share on other sites More sharing options...
falkencreative Posted February 20, 2011 Report Share Posted February 20, 2011 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'"); Quote Link to comment Share on other sites More sharing options...
shoopaie Posted February 20, 2011 Author Report Share Posted February 20, 2011 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.