希望有人能帮我解决这个问题。我有一个表格可以为用户选择所需的类别。我使用此表单的复选框让他们选择类别。在他们选择类别时,我将所选类别保存在 SESSION 上,然后该类别页面重定向到下一页。
这个过程是这样的……
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.
}
我的问题是当页面重定向到下一页(select_subject.php)时,有时用户可能需要使用浏览器上的后退按钮再次返回到类别页面来更改他们选择的类别。但是当它发生时,它不会再次进入类别页面,浏览器会显示类似这样的错误......
文档已过期,此文档不再可用。
注意:但是当我单击页面重新加载按钮时页面显示正常。
在这种情况下,我需要有人帮助避免这种情况,我需要再次显示类别页面,并正确显示先前选择的类别。
更新代码:
<?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>
希望有人帮助我..谢谢..