Page 2 of 3
Posted: Mon Aug 29, 2005 7:55 am
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?
Posted: Mon Aug 29, 2005 8:03 am
by dude81
assumed to means is it expecting the same old variable or is it creating new variable?
Posted: Mon Aug 29, 2005 8:09 am
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
Posted: Mon Aug 29, 2005 8:10 am
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!
Posted: Mon Aug 29, 2005 8:24 am
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
Posted: Mon Aug 29, 2005 8:35 am
by n00b Saibot
where is the next form. post the code for it.
Posted: Mon Aug 29, 2005 8:51 am
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
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Posted: Mon Aug 29, 2005 10:22 am
by feyd
$_POST["to[$i]"]; versus $_POST["to{$i}"]; ?
please start using the highlighting tags appropriately.
Posted: Tue Aug 30, 2005 12:11 am
by dude81
It still gives undefined index as a notice
Posted: Tue Aug 30, 2005 12:28 am
by feyd
you should check if the element exists before trying to display data from it.
isset()
Posted: Tue Aug 30, 2005 12:29 am
by dude81
yes it exists. I echoed it twice
Posted: Tue Aug 30, 2005 12:40 am
by feyd
did you fix the issue I illustrated in my previous post?
Posted: Tue Aug 30, 2005 12:53 am
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

Posted: Tue Aug 30, 2005 12:57 am
by feyd
then
isset() is what you should be using to make sure each element is there before outputing data related to it.
Posted: Tue Aug 30, 2005 1:06 am
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?