On Mon, 19 Jul 2004 14:15:09 -0400 Jason Barnett <[EMAIL PROTECTED]> wrote:
Markus Stobbs wrote:
$message = " Name: $Name Division: $Division Phone: $Phone Email: $Email";
...but when I change $Name and the other variables to $_POST['Name'], I get this error:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /web/scd/vets/Vislab/eventrequest.php on line 94
When you have a variable that is inside a text string (double quotes) like that then you do not need to have the quotes for your array index. So in your case something like this should work:
$message = " Name: $_POST[Name] Division: $_POST[Division] Phone: $_POST[Phone] Email: $_POST[Email]";
I think this is just solving one bad practice (inserting array elements directly in strings) with another (letting undefined constants such as Name pass as variable values).
The problem for Markus is that there's a limit to what kind of variables you can use directly inside strings. In particular, as he noticed, array elements referred by association ($_POST['Name']) won't work.
Not quite true
Your workaround uses a trick: by not enclosing the element identificator (Name) in quotes, it is considered to be a constant. Since there's no constant with that name defined, it evaluates to the name of the constant, which is Name. This is bad practice; the manual page for constants specifically calls it that. And because you don't use quotes to delimitate the identificator, you don't have Markus's problem.
It is completely legal. Name, Division, Phone and Email are not constants, because they are in a string:
"Name: $_POST[Name]"; ^^^^ ^^^^ | | string string
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php