Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
|
Quote:
Originally Posted by chrishirst
No because that would become a string literal of "$email" NOT
'name@email.tld'
|
I have to jump in the wagon here.
This is a PHP quircks (hu, no specialities).
If you use single quotes when you define a string, the $variable is not replaced.
It is only if you use the double quotes:
PHP Code:
$animal="fox"; $string1="the $animal jumps over the lazy dog"; //$string1 is now: //the fox jumps over the lazy dog $string2='the $animal jumps over the lazy dog'; //but $string 2 is now: //the $animal jumps over the lazy dog
But, you can have single quotes in a string, and don't need to concatenate the variables if the "outer" delimiter of the string are double quotes.
In the case of sql queries, this is sensible
PHP Code:
//this is valid, and $email will be replaced by the content of the variable $query="insert into signup(email,zip) values('$email','NA')"; //here, using the single quotes delimiter forces us to concatenate the variable to the string AND escape the query single quotes $query='insert into signup(email,zip) values(\''.$email.'\',\'NA\')';
And if you must use an array indice in your string, then you must enclose it's declaration between { and }
PHP Code:
$animals['dog']='woolfy'; $query="insert into animals (name) values ('{$animals['dog']}');";
__________________
Only a biker knows why a dog sticks his head out the window.
|