...

View Full Version : After form POST browser displays blank page??!!



steamngn
10-27-2006, 09:47 PM
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:

<!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

CFMaBiSmAd
10-27-2006, 10:05 PM
The header("Location: ..."); redirect won't work since content has been output to the browser. Specifically, the following line has already been sent -

<!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 -

error_reporting(E_ALL);

Vsim
10-28-2006, 04:25 AM
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.

steamngn
10-28-2006, 01:58 PM
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

GJay
10-28-2006, 03:44 PM
you need to move the HTML doctype declaration to after the header() call

steamngn
10-28-2006, 04:00 PM
GJay; Did you have to make it so simple?:thumbsup: It's bad enough it was something stupid, now you gotta go and make me feel like an even bigger doof!:eek:
Thanks so much for finding my mistake; things are looking up!
Andy

zoomwebs
02-01-2015, 09:19 AM
Hello!
I have a problem!
In form.php file I put my email adress, but when I test form and press send button - email not send and browser view white page only??
My PHP Code is as follow:-
<?php

if (!empty($_POST)) {

// Used for later to determine result
$success = $error = false;

// Object syntax looks better and is easier to use than arrays to me
$post = new stdClass;

// Usually there would be much more validation and filtering, but this
// will work for now.
foreach ($_POST as $key => $val)
$post->$key = trim(strip_tags($_POST[$key]));

// Check for blank fields
if (empty($post->name) OR empty($post->email))
$error = true;

else {

// Get this directory, to include other files from
$dir = dirname(__FILE__);

// Get the contents of the pdf into a variable for later
ob_start();
require_once($dir.'/pdf.php');
$pdf_html = ob_get_contents();
ob_end_clean();

// Load the dompdf files
require_once($dir.'/dompdf/dompdf_config.inc.php');

$dompdf = new DOMPDF(); // Create new instance of dompdf
$dompdf->load_html($pdf_html); // Load the html
$dompdf->render(); // Parse the html, convert to PDF
$pdf_content = $dompdf->output(); // Put contents of pdf into variable for later

// Get the contents of the HTML email into a variable for later
ob_start();
require_once($dir.'/html.php');
$html_message = ob_get_contents();
ob_end_clean();

// Load the SwiftMailer files
require_once($dir.'/swift/swift_required.php');

$mailer = new Swift_Mailer(new Swift_MailTransport()); // Create new instance of SwiftMailer

$message = Swift_Message::newInstance()
->setSubject('How To Create and Send An HTML Email w/ a PDF Attachment') // Message subject
->setTo(array($post->email => $post->name)) // Array of people to send to
->setFrom(array('no-reply@net.tutsplus.com' => 'Nettuts+')) // From:
->setBody($html_message, 'text/html') // Attach that HTML message from earlier
->attach(Swift_Attachment::newInstance($pdf_content, 'nettuts.pdf', 'application/pdf')); // Attach the generated PDF from earlier

// Send the email, and show user message
if ($mailer->send($message))
$success = true;
else
$error = true;

}

}

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Australian College of Business &amp; Training</title>
<link href="afaq.css" rel="stylesheet" type="text/css" />
<link href="eform.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style2 {
font-size: 12px;
clear: both;
float: left;
width: 70%;
}
.style4 {font-family: Arial, Helvetica, sans-serif}
#username{
padding:3px;
font-size:18px;
border:3px #CCC solid;
}

#tick{display:none}
#cross{display:none}
.style11 {font-size: 12px; font-family: Arial, Helvetica, sans-serif; }
.style13 {font-family: Arial, Helvetica, sans-serif; font-size: 16px; font-weight: bold; font-style: italic; color: #000000; }
.style15 {font-size: Non12e}
.style16 {font-size: 12px}
html, body, h1, h2, h3, h4, h5, h6, p, span, ul, li, div, form, input, select, textarea, button {margin:0; padding:0;}
ul {list-style:none;}
a, a:hover {text-decoration:none; outline:0;}
a img {border:0;}

body {font:12px/16px Verdana, Arial, sans-serif; background:#001F1E;}
#container {width:800px; margin:10px auto; padding:10px; overflow:hidden; border:1px solid #000; border-radius:10px; -moz-border-radius:10px; -webkit-border-radius:10px; background:#F9F9F9;}
#container h1 {margin-bottom:20px; font-size:40px; line-height:40px; font-family:'HelveticaNeue-Light', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-weight:normal;}
.message {margin-bottom:10px; padding:5px;}
.success {color:#4F8A10; border:1px solid #4F8A10; background:#DFF2BF;}
.error {color:#D8000C; border:1px solid #D8000C; background:#FFBABA;}
label {display:block; margin-bottom:3px; cursor:pointer;}
.input, textarea, select, button {display:block; width:390px; margin-bottom:10px; padding:3px; font:22px/22px 'HelveticaNeue-Light', 'Helvetica Neue', Helvetica, Arial, sans-serif; border:1px solid #CCC; border-top-width:2px;}
textarea {font-size:13px; line-height:16px;}
select {width:396px;}
button {float:right; width:auto; margin-bottom:0; padding:3px 30px; cursor:pointer; font-size:16px; border:1px solid #999; border-bottom-width:2px; border-radius:5px; -moz-border-radius:5px; -webkit-border-radius:5px; background:#EEE;}
button:active {border-bottom-width:1px; padding:4px 30px 3px; background:#E9E9E9;}
-->
</style>

</head>

<body>


<div class="enrol_form_box" id="enrol_form_box">
<div id="container">

<h1>The Form</h1>
<?php if ($success) { ?>
<div class="message success">
<h4>Congratulations! It worked! Now check your email.</h4>
</div>
<?php } elseif ($error) { ?>
<div class="message error">
<h4>Sorry, an error occurred. Try again!</h4>
</div>
<?php } ?>
<form method="post" action="" name="form1" id="form1">
<table width="800" align="center" cellpadding="5" cellspacing="2" bgcolor="#FFFFFF">
<tr valign="baseline">
<td width="136" align="right" valign="middle" nowrap="nowrap"><div align="left" class="style2"><span class="style11">Name:</span></div></td>
<td width="346"><input type="text" name="name" id="name" class="input" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td colspan="2" align="right" valign="middle" nowrap="nowrap"><div align="left"><span class="style13">Participant Details</span></div></td>
</tr>
<tr valign="baseline">
<td align="right" valign="middle" nowrap="nowrap"><div align="left" class="style2"><span class="style4">Email:</span></div></td>
<td><input type="text" name="email" id="email" class="input" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">&nbsp;</td>
<td><button type="submit">Submit!</button></td>
</tr>
</table>
<input type="hidden" name="id" value="" />
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p>&nbsp;</p>
</div>


</div>
</div>
</body>
</html>

Can anybody help/guide me please, i am under tension.

zoomwebs
02-01-2015, 09:21 AM
Its working on that website from where i got this script. i wish that after completion, user could get its submitted values in pdf file format. Kindly help me.

zoomwebs
02-01-2015, 09:30 AM
Its working on that website from where i got this script. i wish that after completion, user could get its submitted values in pdf file format. Kindly help me.

zoomwebs
02-01-2015, 09:31 AM
Hello!
I have a problem!
In form.php file I put my email adress, but when I test form and press send button - email not send and browser view white page only??
My PHP Code is as follow:-

<?php

if (!empty($_POST)) {

// Used for later to determine result
$success = $error = false;

// Object syntax looks better and is easier to use than arrays to me
$post = new stdClass;

// Usually there would be much more validation and filtering, but this
// will work for now.
foreach ($_POST as $key => $val)
$post->$key = trim(strip_tags($_POST[$key]));

// Check for blank fields
if (empty($post->name) OR empty($post->email))
$error = true;

else {

// Get this directory, to include other files from
$dir = dirname(__FILE__);

// Get the contents of the pdf into a variable for later
ob_start();
require_once($dir.'/pdf.php');
$pdf_html = ob_get_contents();
ob_end_clean();

// Load the dompdf files
require_once($dir.'/dompdf/dompdf_config.inc.php');

$dompdf = new DOMPDF(); // Create new instance of dompdf
$dompdf->load_html($pdf_html); // Load the html
$dompdf->render(); // Parse the html, convert to PDF
$pdf_content = $dompdf->output(); // Put contents of pdf into variable for later

// Get the contents of the HTML email into a variable for later
ob_start();
require_once($dir.'/html.php');
$html_message = ob_get_contents();
ob_end_clean();

// Load the SwiftMailer files
require_once($dir.'/swift/swift_required.php');

$mailer = new Swift_Mailer(new Swift_MailTransport()); // Create new instance of SwiftMailer

$message = Swift_Message::newInstance()
->setSubject('How To Create and Send An HTML Email w/ a PDF Attachment') // Message subject
->setTo(array($post->email => $post->name)) // Array of people to send to
->setFrom(array('no-reply@net.tutsplus.com' => 'Nettuts+')) // From:
->setBody($html_message, 'text/html') // Attach that HTML message from earlier
->attach(Swift_Attachment::newInstance($pdf_content, 'nettuts.pdf', 'application/pdf')); // Attach the generated PDF from earlier

// Send the email, and show user message
if ($mailer->send($message))
$success = true;
else
$error = true;

}

}

?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum