Hello the DA doesnt mean I am a lawyer

HI,
I have a problem with a form that will send data to my mysql database. It is a work in progress and has many flaws I know. But I will just be happy to get it to work. It half does. I robbed the code and cut and pasted it to get it to where it is now. I can not get it to complete tho. It is a form where a person can enter the grade for his coin and the form will assign a cash value for it and total the whole collection up at the end. Right now it will enter name, email and collection number into database but will only assign 00.00 to every coin. I am trying the option box and even a straight text box for this and nothing works. Mayb e it is because I am using a feild in the database like “coin1” with a num ber?

<form action="" method=“post”>
<table><tr><td>Name: </td><td> <input type=“text” name=“name”></td>
<td>Email:</td><td> <input type=“text” name=“email”></td>
<td>Collection #:</td><td> <input type=“text” name=“collection”><!-- echo next collection number --!></td>

<td>1909 p: </td><td> <input type=“text” name=“coin1”></td>
<td width=“160”>1909 S<BR>
<select name=“coin2”>
<option value=""></option>
<option value=“0.10”>AG</option>
<option value=“1.10”>G4</option>
<option value=“11.00”>F</option>
<option value=“0.10”>EF</option>
<option value=“1.10”>AU</option>
<option value=“11.00”>MS</option>
</select></td>
<td></td><td></td></tr><tr>
<td>1909 s:</td><td> <input type=“text” name=“coin3”></td>
<td>1909 s vdb:</td><td> <input type=“text” name=“coin4”></td>
<td>1910 p:</td><td> <input type=“text” name=“coin5”></td></tr></table>

<input type=“submit” name=“submit” value=“Submit!”>
</form>
<?php
} else {
$name = $_POST[‘name’];
$email = $_POST[‘email’];
$collection = $_POST[‘collection’];
$coin1 = $_POST[‘coin1’];
$coin2 = $_POST[‘coin2’];
$coin3 = $_POST[‘coin3’];
$coin4 = $_POST[‘coin4’];
$coin5 = $_POST[‘coin5’];
mysql_query(“INSERT INTO NEWTRY (name, email, collection, coin1, coin2, coin3, coin4, coin5) VALUES (’$name’, ‘$email’, ‘$collection’, ‘$coin1’, ‘$coin2’, ‘$coin3’, ‘$coin4’, ‘$coin5’ )”);
echo “Success! Your favourite colour has been added!”;
}
?>

The page is located at http://www.permanent-cosmetics-by-debbie.com/ebay/formmysql.php and it does work for name and email and auto-assigns a collection number or auto-increments one if you dont.

Many thanks,
Mike

Hi Mike, welcome!

You are confused about how posting a drop down list works. It only posts one item, and the variable is accessible through the name of name attribute of the [noparse]<select>[/noparse] tag.

With your posted code, this would work:

$coin = $_POST['coin2'];//coin2 is the name value of your select tag

I am assuming you set the default value for your coin1, coin2, coinN columns to 0.00 and that is why that value is being assigned.

If you use the code above, you do not need this code:

 $coin1 = $_POST['coin1'];
$coin2 = $_POST['coin2'];
$coin3 = $_POST['coin3'];
$coin4 = $_POST['coin4'];
$coin5 = $_POST['coin5'];

as these individual values are not accessible from your select. Make sense?

Hello,
I am not following you. For each dropdown box I should use your code just changing the coin2 to what ever coin it is? The form started working on its own…LOL. I must have had something not right but it will soon be a very big form as there are 250 coins in the series.
I was picking up the mysql/php stuff and then got sidetracked and have forgotten most of what little I did learn. I sure like it tho. My goal is to make this form and another to call up the data and total it for users. When I used formmail i got the form to send to email but didnt know how to get it to total the various entrys up into a single dollar figure so I figured that the mysql database would be better. I appreciate the reply a lot.
Many thanks,

Mike Harmon

[quote=actionAction;2327699]Hi Mike, welcome!

You are confused about how posting a drop down list works. It only posts one item, and the variable is accessible through the name of name attribute of the [noparse]<select>[/noparse] tag.

With your posted code, this would work:

$coin = $_POST['coin2'];//coin2 is the name value of your select tag

I am assuming you set the default value for your coin1, coin2, coinN columns to 0.00 and that is why that value is being assigned.

If you use the code above, you do not need this code:

 $coin1 = $_POST['coin1'];
$coin2 = $_POST['coin2'];
$coin3 = $_POST['coin3'];
$coin4 = $_POST['coin4'];
$coin5 = $_POST['coin5'];

as these individual values are not accessible from your select. Make sense?[/quote]

To total it, create a variable that will tally and initialize it to zero:

$total = 0;

then, add the values as you go:

$total += $coinvalues; //or whatever you are adding to the total. Equivalent to total = total + added_value

You can also query your database for the current total, and update it as you go:

$result = mysql_query("SELECT total FROM TABLE_NAME WHERE primary_key = '$current_primary_key'") or die(mysql_error());
$result = mysql_result($result);
$total = $result[0];//now your total is the value stored in the database

//After you have added new values to your $total variable
$update = mysql_query("UPDATE TABLE_NAME SET total = '$total'") or die(mysql_error());

Hope this helps you!