PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?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>
$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>';
}
$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>';
}
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?
<!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:
$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?
<?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.
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
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.
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.
*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!
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