1

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>&nbsp;</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..

TNK
  • 4,263
  • 15
  • 58
  • 81

2 Answers2

1

if you use $_GET method you won't face this problem, change your form method to get and try it.

fkabeer
  • 398
  • 4
  • 15
  • I use $_GET method.. then page category page is loading but with an error message which I use in form validating in category page.. – TNK Jan 19 '13 at 16:20
  • can you show me, your code and error so that i can get the better idea. it is very difficult for me to guess by too little knowledge about your problem. – fkabeer Jan 19 '13 at 18:17
  • you forgot to say something about error which error you are getting. Anyway i have updated my last answer plz check the input style.. – fkabeer Jan 20 '13 at 07:46
  • firefox display like this message with a button of Try again.. Document Expired This document is no longer available. The requested document is not available in Firefox's cache.As a security precaution, Firefox does not automatically re-request sensitive documents.Click Try Again to re-request the document from the website. – TNK Jan 20 '13 at 13:48
  • Chrome display a message like this : Confirm Form Resubmission This webpage requires data that you entered earlier in order to be properly displayed. You can send this data again, but by doing so you will repeat any action this page previously performed. Press Reload to resend that data and display this page. – TNK Jan 20 '13 at 13:50
  • strange, i think u haven't change it in the form tag, did u? your form tag should look like this
    – fkabeer Jan 20 '13 at 18:16
  • No.. I have already changed it. But not working.. @fkabeer, check my question I have updated it with validation code and form's code. my form totally generating dynamically. – TNK Jan 21 '13 at 03:09
  • hi nuwan, i have run your code and i have found no issues in your code. the only thing i am concern about is your redirection. $url = BASE_URI . 'select_subject.php'; plz check this line especially BASE_URI. send me the url on which u ends up i think you are redirecting to the page that do not exist. – fkabeer Jan 21 '13 at 07:47
1

use this code....

if ( $totalCategory >= 1 && $totalCategory <= 10 ) {

    //Replace the following line 
    $_SESSION['category'] = $_POST['category']; 

    //with the line below
    $_SESSION['category'] = $_GET['category'];

    $url = BASE_URI . 'select_subject.php'; // Define the URL:   e fio

        header("Location: $url");
        exit(); // Quit the script. 
}

thanks for sharing your code but you forgot to tell me which error is triggering. lets have a close look for it. Have you declaired the input rightly means

 <input type="checkbox" name="category[]" value="....">
 <input type="checkbox" name="category[]" value="....">
 <input type="checkbox" name="category[]" value="....">

and of course submit

 <input type="submit" name="submitted_category" value="Submit Categories">

and your url should look like this after the submit button is pressed, before you redirect it.

 select-category.php?category[]=2&category[]=3&category[]=7..........

Still alot depends on the error you are getting.

fkabeer
  • 398
  • 4
  • 15