Included form errors when re-submitted on the results page

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

WOWDesigns
New php-forum User
New php-forum User
Posts: 7
Joined: Tue Sep 20, 2011 6:04 am

Included form errors when re-submitted on the results page

Postby WOWDesigns » Tue Sep 25, 2012 2:37 am

Hi all

I have a search form on every page that goes to a certain page to show the results:

Code: Select all

<?php require_once('lib/search_box.php'); ?>


The issue is that when I'm already on the results page and re-submit the form the page fails to load:

PHP:

Code: Select all

if(isset($_POST['spsearch'])) {
      
      $_SESSION['STCode'] = $_POST['STCode'];
      $_SESSION['STSCCode'] = $_POST['STSCCode'];
      $_SESSION['OrderBy'] = $_POST['OrderBy'];
      $_SESSION['PCode'] = strtoupper(str_replace(" ", "", $_POST['PCode']));
      $_SESSION['Distance'] = $_POST['Distance'];
      $_SESSION['BName'] = $_POST['BName'];
      $_SESSION['City'] = $_POST['City'];
      $_SESSION['County'] = $_POST['County'];
      $_SESSION['SrchPage'] = "0";
   
      header("Location: my_results_page.php");
      exit;
      
   } else {
   
   if($_SERVER['REQUEST_URI'] != "") {
         $action = htmlentities($_SERVER['REQUEST_URI']);
   } else {
         $action = htmlentities($_SERVER['PHP_SELF']);
   }


FORM ACTION:

Code: Select all

<form id="search_for_sp" method="post" action="<?php echo htmlentities($action); ?>" onchange="toggle()">


Any ideas? I think it might be because it's sending the user to the page the form is included on already. Is there a way around this please anyone?

As an additional note, when the page fails, if I click refresh - or highlight the url in the browser bar and click return - the page loads with the new content.

Kindest regards
Glynn

kyle04
New php-forum User
New php-forum User
Posts: 94
Joined: Sat Jul 07, 2012 1:36 pm

Re: Included form errors when re-submitted on the results pa

Postby kyle04 » Sat Sep 29, 2012 3:40 pm

Try :
error_reporting(E_ALL);
at the top of the script.
It may identify the problem - maybe with the header:location part ....


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 2 guests

cron