Hope someone help me about this problem.. I have a form to select needed categories for users. I use check boxes for this form to let them to select categories. At the time they selected categories I save that selected categories on SESSION and after that category page redirect to the next page.
That process is something like this...
if ( $totalCategory >= 1 && $totalCategory <= 10 ) {
$_SESSION['category'] = $_POST['category'];
$url = BASE_URI . 'select_subject.php'; // Define the URL:
header("Location: $url");
exit(); // Quit the script.
}
My problem is when page redirect to the next page (select_subject.php) sometimes user may need to go back to the category page again using back button on browser to change their selected category. But when it happen, it is not going to category page again and browsers display an error something like this...
Document Expired, This document is no longer available.
NOTE: But when I click page reload button page display properly.
With this case I need to help from someone to avoid from this and I need to display category page again with displaying previously selected categories properly..
UPDETE CODE:
<?php
if ( isset($_GET['submitted_category'])) {
if ( isset ( $_GET['category']) && is_array( $_GET['category'])) {
$_SESSION['selectedcatcount'] = count( $_GET['category']);
$totalCategory = count( $_GET['category']);
if ( $totalCategory >= 1 && $totalCategory <= 10 ) {
$_SESSION['category'] = $_GET['category'];
$url = BASE_URI . 'select_subject.php'; // Define the URL:
header("Location: $url");
exit(); // Quit the script.
} else {
echo '<div class="error">
<img src="images/error.png" />
<p style="margin:2px 0 0;">Please select atleast 1, not more than 10 categories.</p>
</div>'; }
} else {
echo '<div class="error">
<img src="images/error.png" />
<p style="margin:2px 0 0;">This can not be empty. Please select atleast one category.</p>
</div>';
}
}
$q = 'SELECT * FROM category ORDER BY category_id';
$r = mysqli_query( $dbc, $q);
$c = 0;
$i = 0;
echo '<form action="" method="get" accept-charset="utf-8">';
echo '<table><tr>';
while($row = mysqli_fetch_array( $r, MYSQLI_ASSOC )){
// if remainder is zero after 2 iterations (for 2 columns) and when $c > 0, end row and start a new row:
if( ($c % 2) == 0 && $c != 0){
echo "</tr><tr>";
}
echo '<td width="50%">
<input type="checkbox" name="category[]" value="' . $row['category_id'] . '" />' . $row['category_name'] .
'</td>';
$c++;
} // while..
// in case you need to fill a last empty cell:
if ( ( $i % 2 ) != 0 ){
// str_repeat() will be handy when you want more than 2 columns
echo str_repeat( "<td> </td>", ( 2 - ( $i % 2 ) ) );
}
echo "</tr></table>";
?>
</div>
<div class="continue">
<p>Please click 'Continue' button to proceed to next step</p>
<input type="submit" value="Continue" class="continue-btn" />
<input type="hidden" name="submitted_category" value="TRUE" />
</div>
</form>
Hope someone help me out.. Thank you..