PHP variables inside a variable [closed]
I have an error somewhere in this line of code, if I take "by"
off the line it works fine.
$msg = 'An Order has just been submitted on CID, Number' . $_POST['orderNumber']'by' .$name;
Can any开发者_JS百科one spot my mistake?
I would advise you to utilize one of PHPs core language features. PHP supports variable interpolation in double quoted strings. That's much simpler than the cumbersome string concatenation:
$msg = "An Order has just been submitted on CID, Number $_POST[orderNumber] by $name";
Note that as special exception no array key quotes are to be used there for simple arrays. (Other examples see the manual http://php.net/manual/en/book.strings.php)
Also note that you should actually escape (see htmlspecialchars
) incoming $_POST or $_GET variables, if they are to be used for output again.
Yes, you never concatenate $_POST['orderNumber']
and 'by'
properly (via the .
operator).
$msg = 'An Order has just been submitted on CID, Number ' . $_POST['orderNumber'] . ' by ' . $name; // Notice the . (and a few spaces)
you forgot to concatenate 'by'. Just add the concatenation . infront of 'by'
You for got the .
$_POST['orderNumber'] . 'by'
Try this
$msg = 'An Order has just been submitted on CID, Number'.$_POST['orderNumber'].'by'.$name;
精彩评论