$_SESSION array storage issue
Posted: Sun Aug 11, 2013 11:49 pm
I can't tell what I'm doing wrong here. This form is a multi-stage form on one page; the first form is supposed to be displayed only if $_SESSION['number_people'] is empty. It shows up fine when you first load the page, but when you fill out the form and hit "Next" the page reloads and displays both the first form AND the second form. If you then fill out the second form and click "Next" the first form never shows up again.
The code below is the portion from the beginning, up to just after the problem goes away.
Can someone tell me what I'm doing wrong here?
The code below is the portion from the beginning, up to just after the problem goes away.
Can someone tell me what I'm doing wrong here?
Code: Select all
<?php
if ( empty ( $_SESSION['number_people'] ) ) {
?>
<form method="post" action="">
<h3>Community</h3>
<ul>
<li>How many people are in your family or group? <input class="srs-field" type="text" name="number_people"></li>
</ul>
<input type="submit" value="Next »" style="display: block; margin: 20px 0;">
</form>
<?php
}
if ( isset ( $_POST['number_people'] ) ) {
//store the number of people in variable, strip HTML tags, and eliminate all nun-numeric characters.
$_SESSION['number_people'] = preg_replace( "/[^0-9]/", "", strip_tags( $_POST['number_people'] ) );
?>
<form method="post" action="">
<h3>Water Storage</h3>
<ul>
<li>How much drinking water, in gallons, do you have stored? <input class="srs-field" type="text" name="drinking_water"></li>
</ul>
<input type="submit" value="Next »" style="display: block; margin: 20px 0;">
</form>
<?php
}
if ( isset ( $_POST['drinking_water'] ) ) {
//store the gallons of water in variable, strip HTML tags, and eliminate all nun-numeric characters.
$_SESSION['drinking_water'] = preg_replace( "/[^0-9]/", "", strip_tags( $_POST['drinking_water'] ) );
?>