[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

Post by dude81 »

Or is it that I should name it as to[]{$i} or to[{$i}]
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 »

because it should be echo $_POST['to'.$i].

Look we never use {} outside of "" to print a variable. This construct is only applicable inside "". So correct it and then tell us.
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

<?php for($i=1;$i<=10;$i++)
{
echo $_POST['to'.$i];
echo "<input type=\"hidden\" name=\"to{.$i}\" value=\"{$_POST['to'.$i]}\">";
if(isset($_POST['to'.$i]))
{
echo "<br>";
echo "$_POST['to'.$i]";
}
else
{
echo "not set";
}
}
?>
This results in parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
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 »

Oh boy! You are again making same mistake. See the difference...
On Line #3 -> echo $_POST['to'.$i];
On Line #8 -> echo "$_POST['to'.$i]";
#3 doesn't use "". I've told you before, use {} when printing a var inside of "".

And please use PHP tags, comply to the forum rules or else you will get a serious warning...
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

:wink: thanks, but y is it not getting called in the other form
I call it like this. it doesnt echo the email. whats the msitake im doing here
for($i=1;$i<=10;$i++)
{
$email=$_POST['to'.$i];
echo $email;
{
//some operations;
}
}
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 »

Do you have this app online somewhere so that we can see it or else for debugging put print_r($_POST) on the top of your page and see that all the vars are set properly.
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

No I dont have it online. I was given this to develop it. but gr8 it is getting everything I could see those post variables coming in this fashion.
Array([to{_1}]=> value1 [to{_2}]=> value2...).
but the same array repeating 10 times. So it is getting underscore
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 »

Why does the index have an underscore & why are the braces there ?? Please Post the output as it is and please use the code/php tags to post the code/php segments.
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

Hey got it
u know how to call it
email=$_POST['to_{'.$i.'}'].
so complex.. or is it wrong... But where we are changing it to underscore
Any how output is here
<?php

Array ( [to{_1}] => value1 [to{_2}] => value2 [to{_3}] => value3 [to{_4}] => value4 [to{_5}] => value5 [to{_6}] => value6 [to{_7}] => value7 [to{_8}] => value8 [to{_9}] => value9 [to{_10}] => value10 [message_header] => [message_footer] => [send] => Send this card )
?>
repeating the array 10 times
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 »

So the problem was not entirely with the processing code. it was also in the submitting form too. well, you got it right so continue. Tell us again when you have a prob. ;)
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

ok sure
thank u for the help
Post Reply