This question already has an answer here:
I am repeatedly calling the same page to perform the same action an x amount of times. In the page before this loop, I have a form asking for input. Only the first time when the loop runs I want to use the given value, but when I have the $_POST
in the code, it gives an error.
So I have two questions:
- Does PHP go on with executing the code when 'erroring', if not, is there a way to let it do so, because that would solve my problem.
- Can I skip a piece of the code? Something like
skip lines 12-14
or something...
I could post my code, but I don't think that will make much sense, since I have some other pages too and txt files and such and if you don't know what it is for, it is rather hard to understand.
I will summarize though:
page1.html:
<form action="page2.php" method="post">
<input type="text" name="input">
<input type="submit" value="Submit">
</form>
page2.php:
for($i = 0; $i < $_POST['text']; $i++){
print "<form action=\"page2.php\" method=\"post\">";
}
As you can see, the loop calls page2.php
again, but the $_POST['text']
will not exist anymore. So, is there a way to go around this?
I have tried this:
if($another_counter_from_another_page > 1){
//Do nothing
}
else
{
$_SESSION['counter']=$_POST['text'];
}
And then replace the $_POST['text']
in the for
-loop with $_SESSION['counter']
, but I still get an error even when $another_counter_from_another_page > 1
is true, so that is why I asked for a way to skip a piece of code.
Thank you in advance, I hope my problem is clear from the example I gave...
</div>