Help with this line $_POST[ename$c]

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

Post Reply
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Help with this line $_POST[ename$c]

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try $_POST['ename'.$c]
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Doesn't work. Thanks for helpoing though. It's must appreciated.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

should work, can you post some of the code?
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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 />';
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Thank you very much. That is awesome. Your help is most appreciated.
Post Reply