Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Exclamation After form POST browser displays blank page??!!

    Oh, this is really peeving me to no end...
    I have a page with a form to submit data to MYSQL. There are several scripts on the page. everything on the page works fine including the MYSQL insert, but after the user clicks submit the page is completely blank. The address is ok in the browser bar, and there are no errors on the page. It is just a white, blank page. Any ideas what in the world this could be? The form method is POST, and there is code to redirect back to the page so it doesn't duplicate entries. That seems to work ok. It just doesn't display anything after! The code for this page is long, but here is the top:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <?php 
    // include the database configuration and 
    // open connection to database 
    include './config.php'; 
    include './opendb.php'; 
    
    // check if the form is submitted 
    if(isset($_POST['btnSign'])) 
    { 
        // get the input from $_POST variable 
        // trim all input to remove extra spaces
        
        $gstartdate    = trim($_POST['StartDate']); 
        $genddate      = trim($_POST['EndDate']); 
        $gheadline     = trim($_POST['txtHeadline']); 
        $gheadline     = mysql_real_escape_string($_POST['txtHeadline']);
        $garticle      = trim($_POST['txtArticle']);
        $garticle      = mysql_real_escape_string($_POST['txtArticle']);
        $glinkadrs     = trim("http://www.".$_POST['linkadrs']);
        $glinkadrs     = mysql_real_escape_string("http://www.".$_POST['linkadrs']);  
        $glinktxt      = trim($_POST['txthyperlink']);
        $glinktxt      = mysql_real_escape_string($_POST['txthyperlink']); 
     
        // escape the message ( if it's not already escaped ) 
        if(!get_magic_quotes_gpc()) 
        { 
    
    		$gstartdate = addslashes($gstartdate);
            $genddate   = addslashes($genddate);
            $gheadline  = addslashes($gheadline);
            $garticle   = addslashes($garticle);
            $glinkadrs  = addslashes($glinkadrs);
            $glinktxt   = addslashes($glinktxt);
        } 
         
    
         
        // prepare the query string
    
        $query = "INSERT INTO scroller (StartDate,EndDate, HeadLine, Article, LinkAdrs, TxtHyperLink) " . 
                 "VALUES ('$startdate','$genddate','$gheadline','$garticle','$glinkadrs','$glinktxt')"; 
    
        // execute the query to insert the input to database 
        // if query fail the script will terminate          
        mysql_query($query) or die('Error, query failed. ' . mysql_error()); 
         
        // redirect to current page so if we click the refresh button  
        // the form won't be resubmitted ( as that would make duplicate entries ) 
        header( "Location: http://www.chungmas.com/locked/submit2.php");    
        // force to quite the script. if we don't call exit the script may 
        // continue before the page is redirected 
        exit; 
    } 
    
    ?>
    <html>
    <head>
    
    <script language="javascript" type="text/javascript">
    function limitText(limitField, limitCount, limitNum) {
    	if (limitField.value.length > limitNum) {
    		limitField.value = limitField.value.substring(0, limitNum);
    	} else {
    		limitCount.value = limitNum - limitField.value.length;
    	}
    }
    </script>
    <script type="text/javascript" src="../test/ts_files/calendarDateInput.js">
    
    /***********************************************
    * Jason's Date Input Calendar- By Jason Moon http://calendar.moonscript.com/dateinput.cfm
    * Script featured on and available at http://www.dynamicdrive.com
    * Keep this notice intact for use.
    ***********************************************/
    
    </script>
    	<script language="javascript" src="../test/ts_files/scroll.js"></script>
    <script type="text/javascript" src="../flashobject.js"></script>
    
    <title>Newswire Submit Page</title>
    <link href="../styles/graphics-fullscreen.css" rel="stylesheet" type="text/css">
    <link href="../styles/stylesheet.css" rel="stylesheet" type="text/css">
    <link href="../styles/menu.css" rel="stylesheet" type="text/css">
    <meta name="keywords" content="place your keywords here">
    <meta name="description" content="place a description for your webpage here">
    
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script src="../javascript/special_functions.js" language="JavaScript" type="text/javascript"></script>
    <script src="../javascript/AC_RunActiveContent.js" language="JavaScript" type="text/javascript"></script>
    <script src="../javascript/AC_Macromedia.js" language="JavaScript" type="text/javascript"></script>
    
    <script language="javascript" type="text/javascript">
    // if this page is in:
    //   the root folder, then set this variable to ./
    //   a sub folder one level deep, then set this variable to ../
    //   a sub folder two levels deep, then set this variable to ../../
    var rootFlashLocation = "../";
    var music_on = "0";    // 0 = off, 1 = on
    var clock24hour = "0"; // 0 = 12 hour clock, 1 = 24 hour clock
    </script>
    
    <script language="JavaScript"> 
    /* 
        This function is called when 
        the 'submit' button is pressed 
        Output : true if all input are correct, false otherwise 
    */ 
    function checkForm() 
    { 
        // the variables below are assigned to each 
        // form input  
        var gstartdate, genddate, gheadline, garticle, glink, glinktxt; 
        with(window.document.submitnewsevent) 
        { 
    		gstartdate = StartDate;
            genddate   = EndDate;
            gheadline  = txtHeadline;
            garticle   = txtArticle;
            glinkadrs  = linkadrs;
            glinktxt   = txthyperlink;
            glinkprefix = 'http://www.'  
     
        } 
        // if End Date is empty alert the editor 
        if(trim(gstartdate.value) == '') 
        { 
            alert('Please enter an Starting Date'); 
            gstartdate.focus(); 
            return false; 
        }
        // if End Date is empty alert the editor 
        else if(trim(genddate.value) == '') 
        { 
            alert('Please enter an ending Date'); 
            genddate.focus(); 
            return false; 
        }
            // if Headline is empty alert the editor 
        else if(trim(gheadline.value) == '') 
        { 
            alert('No Headline?! Are you kidding? Think of SOMETHING!'); 
            gheadline.focus(); 
            return false; 
        } 
            // if Article is empty alert the editor 
        else if(trim(garticle.value) == '') 
        { 
            alert('Now why would you submit a Newswire entry with nothing in it? Think of SOMETHING!'); 
            garticle.focus(); 
            return false; 
        }  
        // alert the visitor if link address is not empty and link text is empty  
        else if((trim(glinkadrs.value)!= '') && (trim(gtxthyperlink.value)==''))
        { 
            alert('HEY! You entered a hyperlink without giving it a text name! Try again!'); 
            gtxthyperlink.focus(); 
            return false; 
        } 
     
        else 
        { 
            // when all input are correct  
            // return true so the form will submit         
            return true; 
        } 
    } 
    
    /* 
    Strip whitespace from the beginning and end of a string 
    Input  : a string 
    Output : the trimmed string 
    */ 
    function trim(str) 
    { 
        return str.replace(/^\s+|\s+$/g,''); 
    } 
    
    
    </script>
    
    </head>
    Andy
    (Management+Coworkers)<>Logic

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,028
    Thanks
    2
    Thanked 315 Times in 307 Posts
    The header("Location: ..."); redirect won't work since content has been output to the browser. Specifically, the following line has already been sent -
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    If you put the following line in after your opening <?php tag, the error will be reveled -
    PHP Code:
    error_reporting(E_ALL); 
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    New Coder
    Join Date
    Jul 2005
    Location
    US
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    At a quick glance what CFMaBiSmAd said.
    I do believe
    error_reporting(E_ALL);
    is one of those lovely ini sets that is triggered before the php script. Meaning if you change the ini settings via the php script it won't make a difference (though I may be a bit dated with my php super powers)

    Dunno if this would work.
    ini_set('error_reporting', E_ALL);
    This should though.
    ini_set('display_errors',true);

    A development server should have all error reporting turned on makes life alot easier. Blank screens are common when an error is displayed but all error reporting services are silent, checking the apache logs can be useful in situations like this.

    As for header redirect issues use the php output buffer for similar issues if you don't want to move the first line of code down
    <?php ob_start(); ?>
    starting the output buffer will auto flush the buffer at the end of the script, of course since all data being sent is in the output buffer things like
    header( "Location: http://www.chungmas.com/locked/submit2.php");
    will work.
    a perfect imperfection
    www.hilands.com

  • #4
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts
    I do believe
    error_reporting(E_ALL);
    is one of those lovely ini sets that is triggered before the php script. Meaning if you change the ini settings via the php script it won't make a difference (though I may be a bit dated with my php super powers)

    Dunno if this would work.
    ini_set('error_reporting', E_ALL);
    This should though.
    ini_set('display_errors',true);
    Hey Vsim,
    Right on the money. ini_set('display_errors',true); does the job. There seems to be something wrong with our host's web logs for error reporting the past few days, and so I couldn't figure this out (I'm an SQL guy; php is new to me). After getting the errors to display I have the lovely "Warning: Cannot modify header information - headers already sent" problem. I have gone back and taken out all the whitespace I can find, but still no go. I have a feeling it has something to do with the 'includes' (wild guess on my part). I tried your ob_start suggestion, but no go...
    HELP!!
    Andy
    (Management+Coworkers)<>Logic

  • #5
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    you need to move the HTML doctype declaration to after the header() call

  • #6
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts
    GJay; Did you have to make it so simple? It's bad enough it was something stupid, now you gotta go and make me feel like an even bigger doof!
    Thanks so much for finding my mistake; things are looking up!
    Andy
    (Management+Coworkers)<>Logic


  •  

    Posting Permissions

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