SitePoint Sponsor

User Tag List

Results 1 to 21 of 21
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Header doesn't redirect after form submitted.

    I can't get this form to re-direct after submission. Everything is fired into the database perfect but it just hangs on the page instead of redirecting.
    I get the Header already modified error but I have removed all blank lines and (sadly) all the commented lines before the header. That normally works but in this case not.
    I've run out of ideas. Can anyone else help?

    Here's what I have
    ---------------------
    <?php if (isset ($_GET['startnew']))
    {unset($_SESSION['majorregion']);
    unset($_SESSION['localarea']);}
    if (isset($_GET['majorregion']))
    {$_SESSION['majorregion'] = $_GET['majorregion'];}
    if (isset ($_GET['localarea']))
    {$_SESSION['localarea'] = $_GET['localarea'];}
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
    {if (PHP_VERSION < 6) {$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;}
    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
    switch ($theType) {
    case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "long":
    case "int":
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    break;
    case "double":
    $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
    break;
    case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "defined":
    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
    break;}
    return $theValue;}}
    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
    $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);}
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "fr_lv3_interest")) {
    $insertSQL = sprintf("INSERT INTO levelthreeinterest (core, `white water`, canoe, sea, surf, freestyle, slalom, WWR, touring, polo, racing, localarea, name, email, majorregion) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
    GetSQLValueString($_POST['core'], "int"),
    GetSQLValueString($_POST['ww'], "int"),
    GetSQLValueString($_POST['canoe'], "int"),
    GetSQLValueString($_POST['sea'], "int"),
    GetSQLValueString($_POST['surf'], "int"),
    GetSQLValueString($_POST['freestyle'], "int"),
    GetSQLValueString($_POST['slalom'], "int"),
    GetSQLValueString($_POST['wwr'], "int"),
    GetSQLValueString($_POST['touring'], "int"),
    GetSQLValueString($_POST['polo'], "int"),
    GetSQLValueString($_POST['racing'], "int"),
    GetSQLValueString($_POST['localarea'], "text"),
    GetSQLValueString($_POST['name'], "text"),
    GetSQLValueString($_POST['email'], "text"),
    GetSQLValueString($_POST['majorregion'], "text"));
    mysql_select_db($database_con_pyb, $con_pyb);
    $Result1 = mysql_query($insertSQL, $con_pyb) or die(mysql_error());
    $insertGoTo = "courses-bcu-level3-confirm.php";
    if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];}
    header(sprintf("Location: %s", $insertGoTo));}
    ---------------------

  2. #2
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    You'll need to do some debugging. Try checking to see if your POST variables are all set like you expect them to be.
    I've added such a check near the end of the script.

    If you don't see the contents of your post, then your code isn't getting to the bit that says:
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "fr_lv3_interest")) {

    PHP Code:
    if (isset ($_GET['startnew']))
    {
        unset(
    $_SESSION['majorregion']);
        unset(
    $_SESSION['localarea']);
    }

    if (isset(
    $_GET['majorregion']))
    {
        
    $_SESSION['majorregion'] = $_GET['majorregion'];
    }

    if (isset (
    $_GET['localarea']))
    {
        
    $_SESSION['localarea'] = $_GET['localarea'];
    }

    if (!
    function_exists("GetSQLValueString")) {
        
        function 
    GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue "")
        {
            if (
    PHP_VERSION 6) {
                
    $theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
            }
            
            
    $theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
            switch (
    $theType) {
                
                case 
    "text":
                
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
                break;
                case 
    "long":
                case 
    "int":
                
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
                break;
                case 
    "double":
                
    $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
                break;
                case 
    "date":
                
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
                break;
                case 
    "defined":
                
    $theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
                break;
            }
            
            return 
    $theValue;
        }
        
    }

    $editFormAction $_SERVER['PHP_SELF'];
    if (isset(
    $_SERVER['QUERY_STRING'])) {
        
        
    $editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
    }

    if ((isset(
    $_POST["MM_insert"])) && ($_POST["MM_insert"] == "fr_lv3_interest")) {
        
    // add this:
        
    var_dump($_POST);
        die();
        
    $insertSQL sprintf("INSERT INTO levelthreeinterest (core, `white water`, canoe, sea, surf, freestyle, slalom, WWR, touring, polo, racing, localarea, name, email, majorregion) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
        
    GetSQLValueString($_POST['core'], "int"),
        
    GetSQLValueString($_POST['ww'], "int"),
        
    GetSQLValueString($_POST['canoe'], "int"),
        
    GetSQLValueString($_POST['sea'], "int"),
        
    GetSQLValueString($_POST['surf'], "int"),
        
    GetSQLValueString($_POST['freestyle'], "int"),
        
    GetSQLValueString($_POST['slalom'], "int"),
        
    GetSQLValueString($_POST['wwr'], "int"),
        
    GetSQLValueString($_POST['touring'], "int"),
        
    GetSQLValueString($_POST['polo'], "int"),
        
    GetSQLValueString($_POST['racing'], "int"),
        
    GetSQLValueString($_POST['localarea'], "text"),
        
    GetSQLValueString($_POST['name'], "text"),
        
    GetSQLValueString($_POST['email'], "text"),
        
    GetSQLValueString($_POST['majorregion'], "text"));
        
    mysql_select_db($database_con_pyb$con_pyb);
        
    $Result1 mysql_query($insertSQL$con_pyb) or die(mysql_error());
        
    $insertGoTo "courses-bcu-level3-confirm.php";
        if (isset(
    $_SERVER['QUERY_STRING'])) {
            
            
    $insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
            
    $insertGoTo .= $_SERVER['QUERY_STRING'];
        }
        
        
    header(sprintf("Location: %s"$insertGoTo));


  3. #3
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,411
    Mentioned
    149 Post(s)
    Tagged
    4 Thread(s)
    I get the Header already modified error but I have removed all blank lines and (sadly) all the commented lines before the header.
    Commented and blank lines inside the php tags do not cause the error. It's the blank lines and even spaces outside the php tags that cause it (and of course any output created by php or straight html code).

    Check if there's a space before the opening <?php tag.
    Another cause may be the BOM. See this post for more info: http://www.sitepoint.com/forums/show...s-already-sent

  4. #4
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that. All looks good in the output:

    array(17) { ["name"]=> string(10) "Bob Taylor" ["email"]=> string(17) "bobshouse@aol.com" ["majorregion"]=> string(7) "central" ["localarea"]=> string(4) "east" ["core"]=> string(1) "1" ["ww"]=> string(0) "" ["canoe"]=> string(0) "" ["sea"]=> string(1) "1" ["surf"]=> string(0) "" ["freestyle"]=> string(0) "" ["slalom"]=> string(0) "" ["wwr"]=> string(0) "" ["touring"]=> string(1) "1" ["polo"]=> string(1) "1" ["racing"]=> string(0) "" ["submit"]=> string(6) "Submit" ["MM_insert"]=> string(15) "fr_lv3_interest" }

  5. #5
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for clearing that one up. At least when I fix it I will be able to go back and put all those useful comments back in for future reference.
    However, I've deleted just about every space I can find - even in includes/javascript/jquery files etc.

    I don't quite know how I check the BOM but I do know that normally forms made in this editor do redirect so I guess it's unlikely to be that.

    Any other ideas?

  6. #6
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I still can't get it to redirect. I've take the spaces out of everything and everywhere. What else could it be?
    Help?

  7. #7
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found out how to check the BOM an dI am not 100% sure that isn't the problem.

  8. #8
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    153 Post(s)
    Tagged
    3 Thread(s)
    Right then, next debug section!
    Check if the header is going to the right place.

    PHP Code:
     $insertGoTo "courses-bcu-level3-confirm.php"
        if (isset(
    $_SERVER['QUERY_STRING'])) { 
             
            
    $insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?"
            
    $insertGoTo .= $_SERVER['QUERY_STRING']; 
        } 
         
        
    //header(sprintf("Location: %s", $insertGoTo));

    echo $insertGoTo
    check that the URL is right and its going to the right place.
    Taking the redirect off may also reveal any other errors that might be stopping it.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  9. #9
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks - I've done that.
    The link echoed out is correct but it does have the regions in the address.

    courses-bcu-level3-confirm.php?majorregion=north&localarea=northeast

    Could that be causing the problem?

  10. #10
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just answered my own question by commenting out these lines:
    //$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    //$insertGoTo .= $_SERVER['QUERY_STRING'];}

    and running it. Still no redirection.

  11. #11
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    153 Post(s)
    Tagged
    3 Thread(s)
    Does the page it is going to have any errors?
    Is it getting redirected and then hanging or hanging on the submitted page - check the browser url

    Also I would chuck an exit() call after the header to make sure nothing is still executed.

    PHP Code:
     $insertGoTo "courses-bcu-level3-confirm.php"
        if (isset(
    $_SERVER['QUERY_STRING'])) { 
             
            
    $insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?"
            
    $insertGoTo .= $_SERVER['QUERY_STRING']; 
        } 
         
        
    header(sprintf("Location: %s"$insertGoTo));
    exit(); 
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  12. #12
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I added exit();
    Now I just get 'the white screen of death' after submitting the form and still no redirect.
    Is that what is supposed to happpen?

  13. #13
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That means you are in the submitted page. Is it the same file submitted script page and redirecting one? As already Mike asked, I also suspect you have some warnings which causing to redirect. So try once by putting this on top of the script:
    PHP Code:
    error_reporting(E_ALL E_STRICT);
    ini_set('display_errors'1);

    if (isset (
    $_GET['startnew']))
    {
        unset(
    $_SESSION['majorregion']);
        unset(
    $_SESSION['localarea']);
    }
    ........................... 
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  14. #14
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay,

    That spits out this warning

    Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/mainsite/courses-bcu-level-three-register.php:2) in /Applications/MAMP/htdocs/mainsite/courses-bcu-level-three-register.php on line 61

    But what does that tell me?

  15. #15
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,411
    Mentioned
    149 Post(s)
    Tagged
    4 Thread(s)
    It tells you that at the start of courses-bcu-level-three-register.php there already is output (at or before line 2).
    Is there anything in courses-bcu-level-three-register.php before the first <?php tag? A space, an empty line, html code, anything?

  16. #16
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you included this courses-bcu-level-three-register.php file in other files or this is the file to which the form is submitted to? Check that parent file as well which has included this courses-bcu-level-three-register.php file.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  17. #17
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can't see anything on line 1 or 2
    The submits to itself a few times to create the query. Could that be the problem?

  18. #18
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's line 1 + line 2 anyway:

    <!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <?php require_once('Connections/con_pyb.php');

  19. #19
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So change it to:
    Code html4strict:
    <?php require_once('Connections/con_pyb.php');
    <!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  20. #20
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Done that.
    Now I get this

    Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/mainsite/courses-bcu-level-three-register.php:3) in /Applications/MAMP/htdocs/mainsite/courses-bcu-level-three-register.php on line 59

  21. #21
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Umm I don't know how many files you have included in different files. Just understand the theory: Nothing must not output before some PHP functions like header(). So please put such code which use header() function on top before anything outputted to the browser.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •