Solved

PHP Header(location: mypage.php) directive causes page to crash

Posted on 2014-02-04
9
419 Views
Last Modified: 2014-02-04
I have a corporate Intranet page that asks the user to select a bunch of data to modify by selecting dropdown items and checking off boxes.
The selection is all done in a form.
Upon clicking 'Submit', the page calls itself as an action and validates that at least one checkbox has been checked.  If so, I am okay to go to the next page.
The page works well for data validation, and if I uncomment the echo statements I can see the session varibales that are being set as a a result of data selection.
If i uncomment the header ("location: ....) line, the page crashes.

Any idea what is going on?

    //ini_set('error_reporting', E_ALL);                                      
    session_start();
    include '../Include_Files/ServerSide/connect_qisuser.inc';
    $err = "";
    $shortItems = '';
    $lines_total = count($_SESSION['model_array']);
    
    // If user has submitted form
    if(isset($HTTP_POST_VARS["Submit"])) {
        //$lines_total = count($_SESSION['model_array']);
        //echo $lines_total . "<br />";
        for ($i = 0; $i <= $lines_total; $i++) {
            if (isset($HTTP_POST_VARS["check".$i])) {
                if ($shortItems === '') {
                    $shortItems = $HTTP_POST_VARS["check".$i];
                    $newModelArray = $_SESSION['model_array'][$i];
                }
                else {
                    $shortItems .= "|" . $HTTP_POST_VARS["check".$i];
                    $newModelArray .= "|" . $_SESSION['model_array'][$i];
                }
            }
        }
        
        //echo "<br /><br /><br />";
        //print_r ($shortItems);
        //echo "<br />";
        //print_r ($newModelArray);
        //echo "<br />";
        
        
        if ($shortItems === '') {
            $err = "<br /><br />You must select at least one item to update.";
        }
        
        else {
            $sels = '';
            for ($i=1;$i<21;$i++) {
                if ($sels === '') {
                    $sels = $HTTP_POST_VARS["sel".$i];
                }
                else {
                    $sels .= "|" . $HTTP_POST_VARS["sel".$i];
                }
            }
            
            $_SESSION['shortItems'] = $shortItems;
            $_SESSION['newModelArray'] = $newModelArray;
            $_SESSION['sels'] = $sels;
            //echo "<br /><br />" . $_SESSION['shortItems'] . "<br />";
            //echo $_SESSION['newModelArray'] . "<br />";
            //echo $_SESSION['sels'] . "<br />";
            //header("Location: update20fields.php");
        }        
    }

Open in new window

0
Comment
Question by:dimmergeek
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39832866
What you mean saying 'the page crashes'? What exactly happens?
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39832872
"Crashes" means what, exactly?
0
 
LVL 7

Author Comment

by:dimmergeek
ID: 39832873
if I uncomment the line:

header("Location: update20fields.php");

Open in new window


on line 53 above I get this:

Screen shot
0
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39832884
Is there any browser output at all from the script?
0
 
LVL 7

Author Comment

by:dimmergeek
ID: 39832885
If I leave the line in, the page reloads with no issues.
0
 
LVL 7

Author Comment

by:dimmergeek
ID: 39832890
There is no output sent to the screen upon POSTing the form.
The script just processes form elements, assigns session varibales and is supposed to redirect to the next page for further processing.
0
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 500 total points
ID: 39832891
Could the problem be in update20fields.php? Can you post the code of that page, please?
0
 
LVL 7

Author Comment

by:dimmergeek
ID: 39832910
THAT'S IT!

What was throwing me off was that when I right-clicked on the error page and checked the properties it showed be the address of the calling page, not the destination page!

Thank you!
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39832929
Glad to help you!
Cheers
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question