Forum Moderators: coopster
<form name="bidform" action="insert.php" method="post">
<p>First Name: <input type="text" name="First" /></p>
<p>Last Name: <input type="text" name="Last" /></p>
<p>Bid: $<input type="decimal" name="Bid" /> Do not enter the dollar sign. Whole dollars only.</p>
<input type="submit" value="Submit Bid"/>
</form> <?php
$con = mysql_connect('#*$!x.#*$!x.com', '#*$!x', '#*$!x'); ;
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db(#*$!x);
$sql="INSERT INTO Bids(First, Last, Bid)
VALUES
('$_POST[First]','$_POST[Last]','$_POST[Bid]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
//take user to thank you page after submission//
header("Location: position_auction_ty.shtml");
mysql_close($con)
?>
What do I need to do? Thanks for the help.
<form name="bidform" action="insert.php" method="post">
<p>First Name: <input type="text" name="First" /></p>
<p>Last Name: <input type="text" name="Last" /></p>
<p>Bid: $<input type="text" name="Bid" /> Do not enter the dollar sign. Whole dollars only.</p>
<input type="submit" name="submit" value="Submit Bid"/>
</form>
<?php
//turn on error reporting and make sure this is removed when putting into the public domain
error_reporting(E_ALL);
//check for form submission
if (isset($_POST['submit']) && !empty($_POST['submit'])){
//set up connection
$con = mysql_connect('#*$!x.#*$!x.com', '#*$!x', '#*$!x') or die("Could not connect: ".mysql_error())
mysql_select_db("#*$!x", $con);
//clean your data as your using it directly into DB
$_POST = array_map('trim', $_POST);
$_POST = array_map('mysql_real_escape_string', $_POST);
//convert the bid into integer (if you wish) ensure that the col in the DB is set up to handle this...
$_POST['Bid'] = (int)$_POST['Bid'];
$sql="INSERT INTO `Bids` (`First`, `Last`, `Bid`) VALUES ('".$_POST['First']."','".$_POST['Last']."','".$_POST['Bid']."')";
//issue the query
if (mysql_query($sql,$con)){
//take user to thank you page after submission//
header("Location: position_auction_ty.shtml");
exit;
}
else{
//the way your doing this, you need to have the else here so that you can handle any failure.
die('Error: ' . mysql_error());
exit;
}
//no need to use mysql_close as this is the default action when the script has been excecuted
}
else{
//failed, so redirect user back to form
header("location: YOUR_FORM_FILENAME_HERE.php");
exit;
}
?>