[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 »

But it worked for me here as the form was in loop which I closed
Should I try now curly braces?,
where exactly I shoould put them if so?
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

assumed to means is it expecting the same old variable or is it creating new variable?
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

Yo Gr8
Curly braces thing worked very fine.
Thanks n00b Saibot, feyd and moderator I think I needed that. It was getting value previoulsy but in tyhe form it vopuldnt get.
Many thanks to the forum
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 »

use them like this

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><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\">"; 
?>
always use echo "Text and a {$var}" instead of echo "Text and a $var" when echoing. It tells PHP to treat enclosed thing as a variable.

and no, it does not create new variable.

edit: oh great! thread already responded. This 1-minute response slag doesn't let go of me. why? i think d11wtq knows, eh! ;)
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

looked fine till next form, what should I call the same name in the other form.
is it $_POST['to'.$i] or something else.
the above one gives notices as undefined index to1..to10 and undefined variable to?
then how to call the name now
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 »

where is the next form. post the code for it.
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

Code: Select all

<?php
else if(isset($_POST["send"]))
        {
        $message_header = $_POST["message_header"];
        $message_footer = $_POST["message_footer"];
        for($i=1;$i<=10;$i++)
        {
        $email=$_POST['to{$i}'];//here is the variable name I want to call
        echo $email;
                {
                //$sql1="UPDATE auto_invite SET sent='Y', date_time=current_timestamp(), ip_address=$_SERVER['REMOTE_ADDR'], distributor_id=$dsa WHERE email_id=$_POST[to$i]";
                mysql_connect("localhost", "root", "") or
                die("Could not connect: " . mysql_error());                 mysql_select_db("test");
         $result1=mysql_query($sql1);

      $to             = $_POST["to[$i]"];
        $content ="<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>
        <html>
        <head>
        <title>:: THE SAI ::</title>
        <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
        </head>

        <body style='font-family:Verdana, Arial, Helvetica, sans-serif; cursor:default; font-size:14px ' onSelectStart='return false' onContextMenu='return false'>
        <table width='200' height='190' border='0' align='center' cellpadding='10'>
        <tr>         <td width='800' height='10' align='left' valign='middle' bgcolor='#FFF4F4'>$message_header</td>
        </tr>
  
        <tr>
        <td width='800' height='10' align='left' valign='middle' bgcolor='#FFF4F4'>$message_footer<br>

        </td>
        </tr>

        </table>
        </body>
        </html>";

        sendmail($to,$subject, $content, $headers);
?>

feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$_POST["to[$i]"]; versus $_POST["to{$i}"]; ?

please start using the highlighting tags appropriately.
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

It still gives undefined index as a notice
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you should check if the element exists before trying to display data from it. isset()
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

yes it exists. I echoed it twice
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

did you fix the issue I illustrated in my previous post?
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

yes I did. I tried to call the name there in the before itself. It is giving there to same notice .
Undefined index. to1 :roll:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

then isset() is what you should be using to make sure each element is there before outputing data related to it.
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]."\">";
echo "<input type=\"hidden\" name=\"to{$i}\" value=\"{$_POST['to'.$i]}\">";
if(isset($_POST["to{$i}"])
echo $_POST["to{$i}"];
}
?>
it give parse error at echo $_POST["to{$i}"];
what should I do?
Post Reply