0

i have this code. the looping code. but i dont know how to pass the value to the next page. help me please! :P

<?php

$req = $_POST['req'];

echo "<form>";


echo "</form>";
$i=1;

while($i <= $req) {
    echo "<label>Requirement " . $i . " :</label><br/";
    echo "<input name=\"req".$i."\" type=\"text\" /> <br />";
    $i++;
}

echo "<br />";
echo "<input name=\"submit\" type=\"submit\" />";

?>

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
5
Views
8 Years
Discussion Span
Last Post by cwarn23
0

Welcome to daniweb. I would suggest placing the value in a hidden field where when the next field is submitted it will then again be added to the $_POST array. So the following is an example:

<?php
$req = $_POST['req'];

echo '<form>';
for ($i=1; $i <= $req; $i++) {
echo '<label>Requirement ' . $i . ' :</label><br/>';
echo '<input name="req'.$i.'" type="text" /> <br />';
}
echo '<br /><input name="submit" type="submit" />';
echo '<input type="hidden" name="req" value="'.$_POST['req'].'"></form>';
?>

Second page

$req=$_GET['req'];

I also fixed a html bug in your code and changed the loop to make it run faster. And please use code tags.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.