I'm trying to create a script that allows people to bid on items they want to purchase, and then email that information. The textbox name is generated from the ID number of the item from mysql. I'm not sure how to print all of the item names and amounts in the body of the email given this. Please take a look at the script below:
Select the items for which you would like to make an offer.
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table>
<tr><td>Enter your email address:</td><td><input type="text" name="email" size="20"></td></tr>
<tr><td>Enter your name:</td><td><input type="text" name="name" size="20"></td></tr>
<?php
require_once ('../files/mysql_connect.php');
//Create the item name list
$query="SELECT ID, item_Name, item_Category, Current_Reg FROM itemnames WHERE Sold='N' ORDER BY item_Name
ASC";
$result=@mysql_query ($query);
while ($row=mysql_fetch_array ($result, MYSQL_ASSOC))
{
echo '<tr><td>'.$row['item_Name'].'</td>
<td><input type="text" name=items["'.$row['item_Name'].']" size="10"><td><tr>';
}
mysql_close();
?>
<tr><td colspan="2"><input type="Submit" name="Submit" value="Submit"></td></tr>
</form>
<?php
if (isset($_POST['Submit'])) {
if (strlen($_POST['name'])>0) {
$name=TRUE;
} else {
$name=FALSE;
echo '<P>You forgot to enter your name</p>';
}
if (strlen($_POST['email'])>0) {
$email=TRUE;
} else {
$name=FALSE;
echo '<p>You forgot to enter your email address</p>';
}
if ($name && $email) {
$body = 'You bid on the following items:'."\n";
foreach($_POST['items'] as $item_Name => $bid)
{
if(!empty($bid))
{
$body = $item_Name.' = $'.$bid."\n";
}
}
$from=($_POST['email']);
mail (me@me.com','Offer Made',$body,'From:'.$from);
echo 'Mail sent';
}else{
echo 'Please try again';
}
}
?>
But this code will only print the last item that was bid on in the email.
If I have: Cookies, Jars, Bugs, Bowls, and Towels, and a user bid on all 5, it'll only print "Towels = $2.00" in the email. Can someone help?