Page 1 of 1

Help with this line $_POST[ename$c]

Posted: Sat Feb 15, 2003 8:50 pm
by nigma
Is anyone willing to help me get the post variable ename followed by the variable $c? The variable c contains the current item I that I am on, and the post variables are all ename1, ename2, ename3(c contains these number). So I want it to print out the post variable that the program is on.

Thanks for all help provided.

Posted: Sat Feb 15, 2003 8:53 pm
by volka
try $_POST['ename'.$c]

Posted: Sat Feb 15, 2003 9:01 pm
by nigma
Doesn't work. Thanks for helpoing though. It's must appreciated.

Posted: Sat Feb 15, 2003 10:21 pm
by volka
should work, can you post some of the code?

Posted: Sun Feb 16, 2003 12:04 am
by nigma
Here it is:

<html>
<body bgcolor="999999" text="black">

<div align="left">

<h2>Add Unapreciated person confirmation</h2>

<br>

<?php

$cnt = 0;

if ($_POST[yname] != "") {
echo("For the posters name you entered: <strong>$_POST[yname]</strong><br><br>");
}

if ($_POST[ename1] != "") {

$cnt++;
echo("For unapreciated person #1 you entered: <strong>$_POST[ename1]</strong><br>");
}

if ($_POST[ename2] != "") {

$cnt++;
echo("For unapreciated person #2 you entered: <strong>$_POST[ename2]</strong><br>");
}

if ($_POST[ename3] != "") {

$cnt++;
echo("For unapreciated person #3 you entered: <strong>$_POST[ename3]</strong><br>");
}
if ($cnt == 0)
{
die("You did not fill in any other fields. Please go back: <a href=\"addEform.php\" accesskey=a>Add Unapreciated Person</a>");
}
?>

<p><h3><br>If this information is incorrect then enter the corrected info in the following form.</h3></p>

<form action="addEnemy.php" method="POST">

<?php

echo ("Poster's name: <input type=\"text\" name=yname value=$_POST[yname]><br><br>");

$c = 0;

for ($i = 0;$i < $cnt; $i++)
{
$c++;
echo("Unapreciated person #$c: <input type=\"text\" name=ename$c value=$_POST['ename'.$c]><br><br>");
}

?>
<input type="submit" value="Continue with entered information">
</form>

</div>

</body>
</html>

Now this is meant as sort of a confirmation page for what you filled out in the last form. The last form has 4 input boxes. 1 for your name, and three more titled ename1-3.

Posted: Sun Feb 16, 2003 4:26 am
by volka
echo("Unapreciated person #$c: <input type=\"text\" name=ename$c value=$_POST['ename'.$c]><br><br>");
if you're in a string literal you need to perform a complex expression replacement.
In this case try

Code: Select all

echo("Unapreciated person #$c: <input type="text" name=ename$c value={$_POST['ename'.$c]}><br><br>");
or

Code: Select all

echo 'Unapreciated person #', $c, ': <input type="text" name="ename', $c, '" value="', $_POST['ename'.$c], '" /><br /><br />';

Posted: Sun Feb 16, 2003 12:31 pm
by nigma
Thank you very much. That is awesome. Your help is most appreciated.