[SOLVED] unexpected T_ENCAPSED_AND_WHITESPACE,

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

[SOLVED] unexpected T_ENCAPSED_AND_WHITESPACE,

Post by dude81 »

Hi,
Im getting error parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
and the line where it is pointing is
as follows

echo "<input type=\"hidden\" name=\"to.$i\" value=\"$_POST['to'.$i]\">";

but I dont find this wrong as per my knowledge,but vi editor and browser show there is an error here.
Can someone help me.

Dude81
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Check the lines of code before the indicated point. Comment out lines until the error goes away. Look for lines that don't terminate correctly. You'll find it. :wink:

FYI use the php tags when posting code.
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Here is the thing.

Post by dude81 »

Hey I counted all the braces but still no result this is the thing

Code: Select all

<form name="preview_form" action="tinvite_health.php" method="POST">
        <?
        $message_header = nl2br($_REQUEST["message_header"]);
        $message_footer = nl2br($_REQUEST["message_footer"]);
        for($i=1;$i<=10;$i++)
        {
                echo $_POST['to'.$i];
                echo "<br>";
                {

                echo "<input type=\"hidden\" name=\"to.$i\" value=\"$_POST['to'.$i]\">";
                echo "<input type=\"hidden\" name=\"message_header\" value=\"$message_header\">";
                echo "<input type=\"hidden\" name=\"message_footer\" value=\"$message_footer\">";
        }
        }
        ?>
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Code: Select all

<form name="preview_form" action="tinvite_health.php" method="POST">
        <?
        $message_header = nl2br($_REQUEST["message_header"]);
        $message_footer = nl2br($_REQUEST["message_footer"]);
        for($i=1;$i<=10;$i++)
        {
                echo $_POST['to'.$i];
                echo "<br>";
                

                echo "<input type=\"hidden\" name=\"to.$i\" value=\"$_POST['to'.$i]\">";
                echo "<input type=\"hidden\" name=\"message_header\" value=\"$message_header\">";
                echo "<input type=\"hidden\" name=\"message_footer\" value=\"$message_footer\">";
        }
        ?>
You had some extra curly braces in there.
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Not solved yet

Post by dude81 »

Certainly I was doing a mistake there, but it doesnt seem the error.
The same error message repeats still

dude81 :cry:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the issue is the $_POST variable in that line. Because you are using dynamic indices, you should jump out of the string to get the variable, then jump back into the string.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Everything looks fine in my code and shouldn't be outputting that error although feyd is right, your dynamic variable in the double quotes wont work correctly like that - still shouldn't error though.

What does your code look like now?
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

Code: Select all

<form name="preview_form" action="tinvite_health.php" method="POST">
        <?
        $message_header = nl2br($_REQUEST["message_header"]);
        $message_footer = nl2br($_REQUEST["message_footer"]);
        for($i=1;$i<=10;$i++)
        {
                echo $_POST['to'.$i];
                echo "<br>";
                 echo "<input type=\"hidden\" name=\"to.$i\" value=\"$_POST['to'.$i]\">";
          }
                echo "<input type=\"hidden\" name=\"message_header\" value=\"$message_header\">";
                echo "<input type=\"hidden\" name=\"message_footer\" value=\"$message_footer\">";
        
        
        ?>
d11wtq | Please put

Code: Select all

tags around your php code [/color]
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

Oops I submitted b4 I wrote...
then how to use POST there
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Code: Select all

<form name="preview_form" action="tinvite_health.php" method="POST">
        <?
        $message_header = nl2br($_REQUEST["message_header"]);
        $message_footer = nl2br($_REQUEST["message_footer"]);
        for($i=1;$i<=10;$i++)
        {
                echo $_POST['to'.$i];
                echo "<br>";
                 echo "<input type=\"hidden\" name=\"".'to'.$i."\" value=\"".$_POST['to'.$i]."\">";
          }
                echo "<input type=\"hidden\" name=\"message_header\" value=\"$message_header\">";
                echo "<input type=\"hidden\" name=\"message_footer\" value=\"$message_footer\">";
        
        
        ?>
It's probably easiest to use single quotes ' ' and to concatenate using the dot syntax I used above but basically you need to use a "." to jump out of string mode and parse the varibel then another "." to go back into the string.

Concatenation in PHP


feyd | forgot to quote 'to' in that bit. :)
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

Hey Feyd and d11wqt,
I didnt get what jumping out the string and back in means. But when Im echoing that before the form, I could get the values
Then Y is wront there? :?:
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

Code: Select all

echo "<input type=\"hidden\" name=\"to.$i\" value=\"$_POST['to'.$i]\">";
This is wrong, the value=\"$_POST['to'.$i]\" bit.
If you want to write it as it is you should surround it with {}, which you should have done in 1st place.
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

It gives now a notice saying
Notice: Use of undefined constant to-assumed to in my path
what does this mean. Is it taking the originally paased 'to' from the other form
??
Thanks for the gr8 help
Thanks for ur forum helping so greatly begginers in PHP
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'm not sure that alone will work..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try copying d11wtq's code again, it had that error in it.
Post Reply