View Single Post
  #2 (permalink)  
Old January 6th, 2004, 08:45 PM
nikolai nikolai is offline
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts

You're not consistent with your quoting style.

When substituting an string-indexed array element in a double-quoted string, you don't need to quote the index:


$person = array("name" => "Nikolai", "city" => "San Diego");
echo "His name is $person[name]."


That's because within a string, if PHP sees a variable identifier (e.g. $person, $foo) followed by an opening square bracket, PHP assumes that the variable is an array, and that the index is everything up to the first closing square bracket.

This index can either be a number, a string, or another variable. A single-quote mark is an invalid character to begin a simple string index, so PHP throws an error.

To accomodate more complex string or nested indexes, PHP supports the curly-brace syntax. Within curly braces, you must quote all your indexes as if you were not within a double-quoted string.

To make a long story short, you need to either remove the single-quotes from $_POST['text1'], or put $_POST['text1'] in curly-braces.

For more information, I strongly suggest you read this page:

Take care,

Reply With Quote