Page 1 of 3

[SOLVED] unexpected T_ENCAPSED_AND_WHITESPACE,

Posted: Mon Aug 29, 2005 6:33 am
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

Posted: Mon Aug 29, 2005 6:41 am
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.

Here is the thing.

Posted: Mon Aug 29, 2005 6:53 am
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\">";
        }
        }
        ?>

Posted: Mon Aug 29, 2005 6:58 am
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.

Not solved yet

Posted: Mon Aug 29, 2005 7:05 am
by dude81
Certainly I was doing a mistake there, but it doesnt seem the error.
The same error message repeats still

dude81 :cry:

Posted: Mon Aug 29, 2005 7:15 am
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.

Posted: Mon Aug 29, 2005 7:19 am
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?

Posted: Mon Aug 29, 2005 7:25 am
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]

Posted: Mon Aug 29, 2005 7:26 am
by dude81
Oops I submitted b4 I wrote...
then how to use POST there

Posted: Mon Aug 29, 2005 7:30 am
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. :)

Posted: Mon Aug 29, 2005 7:32 am
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? :?:

Posted: Mon Aug 29, 2005 7:40 am
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.

Posted: Mon Aug 29, 2005 7:43 am
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

Posted: Mon Aug 29, 2005 7:45 am
by feyd
I'm not sure that alone will work..

Posted: Mon Aug 29, 2005 7:47 am
by feyd
try copying d11wtq's code again, it had that error in it.