Page 1 of 2

PHP Rookie - Getting blank page. What am I doing wrong?

Posted: Sun Oct 30, 2005 5:22 pm
by hawkfire
Hello again. When I launch this page, I'm getting a blank screen. The full code is below.

Code: Select all

<?php 
$postItemNum='0123';
if (isset($_POST['submit'])) { // Handle the form.

	$message = NULL; // Create an empty new variable.
	
	// Check for a name.
	if (strlen($_POST['$Firstname']) > 0) {
		$Firstname = TRUE;
	} else {
		$Firstname = FALSE;
		$message .= '<p>You forgot to enter your first name!</p>';
	}
	
	// Check for an email address.
	if (strlen($_POST['email']) > 0) {
		$email = TRUE;
	} else {
		$email = FALSE;
		$message .= '<p>You forgot to enter your email address!</p>';
	}

	// Check for a Lastname.
	if (strlen($_POST['Lastname']) > 0) {
		$Lastname = TRUE;
	} else {
		$Lastname = FALSE;
		$message .= '<p>You forgot to enter your last name!</p>';
	}
	$Bid=0.00;
	$Bid=$Bid+$_POST['BidAmount'];
	//Check for five dollar increments
	if ($Bid]%5)=0 {
		$FiveDollar=TRUE;
	} else {
		$FiveDollar=FALSE;
		$message .='<p>All bids must bid in units of $5!</p>';
}
	
$FiveDollar=TRUE;
$HighBid=TRUE;
if ($Firstname && $email && $Lastname && $HighBid && $FiveDollar) { // If everything's okay.
$message .='The bid worked.';
}

}
// Set the page title and include the HTML header.
?>
<html>
<body>


<?
// Print the error message if there is one.
if (isset($message)) {
	echo '<font color="red">', $message, '</font>';
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset><legend>Place Your Bid:</legend>
<p><?php
require_once ("mysql_connect.php");	
// Make the query.
$query = "SELECT ItemNum,ItemDesc,HighBid FROM SA_Items where ItemNum='".$postItemNum."'";
$result = @mysql_query ($query); // Run the query.
echo "<table border=1><tr><td><b>ItemNum</b></td><td width=200><b>Item Description</b></td><td><b>Current Bid</b></td></tr>";
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
		echo "<tr>";
		echo "<td align=\"left\">$row[0]</td>";
		echo "<td align=\"left\">$row[1]</td>";
		echo "<td align=\"left\" width=\"200\">$row[2]</td>";
	}
mysql_free_result ($result); // Free up the resources.	
mysql_close(); // Close the database connection.
?></tr></table></p>
<p><b> First Name:</b> <input type="text" name="Firstname" size="20" maxlength="40" value="<?php if (isset($_POST['Firstname'])) echo $_POST['Firstname']; ?>" /></p>
<p><b> Last Name:</b> <input type="text" name="Lastname" size="20" maxlength="40" value="<?php if (isset($_POST['Lastname'])) echo $_POST['Lastname']; ?>" /></p>
<p><b>Email Address:</b> <input type="text" name="email" size="40" maxlength="60" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /> </p>
<p><b>Enter Bid:</b> <input type="text" name="BidAmount" size="40" maxlength="60" value="<?php if (isset($_POST['BidAmount'])) echo $_POST['BidAmount']; ?>" /> </p>

</fieldset>

<div align="center"><input type="submit" name="submit" value="Submit Information" /></div>

</form><!-- End of Form -->
</body>
</html>
The portion that is causing the problem is:

Code: Select all

$Bid=0.00;
	$Bid=$Bid+$_POST['BidAmount'];
	//Check for five dollar increments
	if ($Bid]%5)=0 {
		$FiveDollar=TRUE;
	} else {
		$FiveDollar=FALSE;
		$message .='<p>All bids must bid in units of $5!</p>';
}
What am I doing wrong?

Posted: Sun Oct 30, 2005 5:28 pm
by Chris Corbyn
Syntax error:

Code: Select all

if ($Bid]%5)=0 {
Notice the bracket after $Bid?

Put

Code: Select all

error_reporting(E_ALL);
on the top line of your scripts while you develop, then remove when happy to realease it.

Posted: Sun Oct 30, 2005 5:32 pm
by hawkfire
error_reporting(E_ALL);
That should be in bold letters on the top of every page of every PHP book ever written! Thank you so much!

Posted: Sun Oct 30, 2005 5:42 pm
by hawkfire
....except I removed the bracket:

Code: Select all

$Bid=0.00;
	$Bid=$Bid+$_POST['BidAmount'];
	//Check for five dollar increments
	if ($Bid%5)=0 {
		$FiveDollar=TRUE;
	} else {
		$FiveDollar=FALSE;
		$message .='<p>All bids must bid in units of $5!</p>';
}
added the line of code you mentioned:

Code: Select all

<?php 
error_reporting(E_ALL);
$ErrorMessage = 'An error occured in script '.__FILE__.' on line '.__LINE__."\n";
error_log ($ErrorMessage, 3, 'errors.txt');
and I'm still getting a blank page. No errors on screen and no errors in the file.

Posted: Sun Oct 30, 2005 5:53 pm
by Chris Corbyn
Try doing a print_r($_POST); outside of any "if" conditions. Perhaps something isn't transferring as expected. Is the page totally blank? Anything in the html source code produced?

Posted: Sun Oct 30, 2005 6:02 pm
by hawkfire
Completely blank.

The HTML produced is:

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
<BODY></BODY></HTML>
in IE.

I thought it might be a problem with the $_POST['BidAmount'], so I changed the code to read:

Code: Select all

$Bid=FLOATVAL($_POST['BidAmount']);
	//Check for five dollar increments
	if (FMOD($Bid,5))=0 {
		$FiveDollar=TRUE;
	} else {
		$FiveDollar=FALSE;
		$message .='<p>All bids must bid in units of $5!</p>';
}
and it still won't work. How would you validate that the bid amount is a multiple of 5?

Posted: Sun Oct 30, 2005 6:06 pm
by yum-jelly
This is still wrong....

Code: Select all

if ($Bid%5)=0 {

Code: Select all

<?php

if ( $Bid % 5 == 0 )
{
	$FiveDollar = TRUE;
}
else
{
	$FiveDollar = FALSE;
	$message .= '<p>All bids must bid in units of $5!</p>';
}

?>

yj

Posted: Sun Oct 30, 2005 6:22 pm
by hawkfire
yum-jelly wrote:This is still wrong....

Code: Select all

<?php

if ( $Bid % 5 == 0 )
{
	$FiveDollar = TRUE;
}
else
{
	$FiveDollar = FALSE;
	$message .= '<p>All bids must bid in units of $5!</p>';
}

?>
Still getting the blank page, although I'm sure that's one less error in my code.

Posted: Sun Oct 30, 2005 6:26 pm
by Chris Corbyn
Note: If error_reporting(E_ALL); has made no difference you may also need to put:

Code: Select all

ini_set('display_errors', 'On');
Along with that. Alternatively, if you have access to the php.ini file you can set those values in there by default ;)

Posted: Sun Oct 30, 2005 6:32 pm
by hawkfire
This is getting beyond frustrating:

Code: Select all

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 'On');
$ErrorMessage = 'An error occured in script '.__FILE__.' on line '.__LINE__."\n";
error_log ($ErrorMessage, 3, 'errors.txt');
$postItemNum='0123';
print_r($_POST);
if (isset($_POST['submit'])) { // Handle the form.
Still no error, still no page. As the charity auction starts tomorrow, I'm setting up a temporary manual bid system in the mean time. I've at least got a page that can list the contents of the database, even if I cannot directly update it yet. Any continued help on this is GREATLY appreciated.

Posted: Sun Oct 30, 2005 10:49 pm
by mickd
just something else i noticed

Code: Select all

if ($Bid]%5)=0 { 
        $FiveDollar=TRUE; 
    } else { 
        $FiveDollar=FALSE; 
        $message .='<p>All bids must bid in units of $5!</p>'; 
} 
     
$FiveDollar=TRUE; 
$HighBid=TRUE;
having

$FiveDollar=TRUE;
$HighBid=TRUE;

after the if statement kinda defeats the purpose of having the if statement as it will always be set to true no matter what the if statement will return.

EDIT: another side note, should be consistent with tags and have all php opening tags written the long way

Code: Select all

<? 
// Print the error message if there is one.
EDIT2: might want to try every line or 2 echo a number (that increases) so you know where the script screws up.

EDIT3: FOUND AN ERROR

Code: Select all

if ($Bid]%5)=0 { 
        $FiveDollar=TRUE; 
    } else { 
        $FiveDollar=FALSE; 
        $message .='<p>All bids must bid in units of $5!</p>'; 
}
theres no closing and opening bracket for the if statement and it should be 2 equal signs.
1 equal sign assigns the right value to the left, 2 equal signs checks if the values are equal and 3 equal signs checks if the value and type is equal.

Code: Select all

if ($Bid]%5)=0 { 
//should be
if (($Bid]%5)==0) {

Posted: Mon Oct 31, 2005 12:01 am
by AGISB
I would first get rid of that nested HTML PHP mixture. Simply put all in one php tag and use echo to output the html.

You also condition the whole output on the conditioned output of other variables. You use $_POST['submit']. I think that might already be the problem. If you just use a button with value submit. I am not really sure if that even has a value depending on certain browsers. If not you sure got no output as all conditions will turn false.

Posted: Mon Oct 31, 2005 12:13 am
by Charles256
yeah man..just changing .

Code: Select all

if (($Bid%5)==0) {
        $FiveDollar=TRUE;
    } else {
        $FiveDollar=FALSE;
        $message .='<p>All bids must bid in units of $5!</p>';
}
got it to display:-D update us plaese.we like knowing we helped;)

Posted: Mon Oct 31, 2005 4:52 am
by hawkfire
Charles256 wrote:yeah man..just changing .

Code: Select all

if (($Bid%5)==0) {
        $FiveDollar=TRUE;
    } else {
        $FiveDollar=FALSE;
        $message .='<p>All bids must bid in units of $5!</p>';
}
got it to display:-D update us plaese.we like knowing we helped;)
I tried that, but still got a blank page. The lines:

Code: Select all

$FiveDollar=TRUE;
$HighBid=TRUE;
*are* redundant, but I'm still in debug mode - they'll be removed from the final version.
AGISB wrote:I would first get rid of that nested HTML PHP mixture
I think that is my next step - rewrite the code. Most of the page was written by hacking a code sample from a book. If I start fresh, I'm likely to notice where I messed it up.

I will definitely keep you posted. Thanks for all of your help!

Posted: Mon Oct 31, 2005 7:27 am
by shiznatix
what i found to be a really good idea was just install php and apache and mysql on your own computer then you can have complete access to you php.ini file and make everything just how it should be and then once you make everything nice and pretty move it to the server where they may turn off ini_sets and whatnot. that way you can see all errors and update everything really fast no problems