开发者

PHP variables inside a variable [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜