PHP_Mysql <select> problem? Hi all, i'm new to PHP and i don't know if i can ask questions here or not but i have a little store i want in the databse to store the avilable amount of a product, and list it in a <select> statemnet, when the user choose from the select list , the number is stored in the databse so that i can retrieve it later. i want this process to repeat for all the products i have i started a code , but i couldn't know how to store the selection that the user choose <?php mysql_connect("localhost"); mysql_select_db("db"); $sql = "SELECT * FROM store"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) { $p = $row[p]; $av = $row[av]; $price = $row[price]; echo "<tr> <td>$p</td> <td><select name=".$choice.">"; for($i=0; $i<=$avilable; $i++) { echo "<option value=".$i." name=".$i.">$i</option>"; } echo "<td >$price</td> </tr>"; } mysql_close(); ?> Code (markup): after that when i click submit i want a page that prints out for every product the amount that the user choose + the price and the total price i hope you can help me
Do you mean to select multiple item and insert them in to SQL database? Take a look at this example: HTML PHP
inanobot thanx 4 ur reply i have multiple <select> statements I have a homework for calculating the invoice of multiple products the quantity of the products is stored in a DB and i retrieve them from the DB to the select statement product1: <select>(select from 0 untill the quantity stored in DB): price product2: <select>: price product3: <select>: price ... product n: <select>: price So, i have a problem when i hi the submit button, i don't know how to store what the user choose from every select and how to store it in the Database
is this what you wanted? <?php mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("db") or die(mysql_error()); if(isset($_POST['submit'])) { $choice = $_POST['choice']; mysql_query("INSERT INTO tablename (choice) VALUES('$choice') ") or die(mysql_error()); } $query = "SELECT * FROM store"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { $p = $row[p]; $av = $row[av]; $price = $row[price]; ?> <form action="" method="post"> <?php echo "<tr> <td>$p</td> <td><select name='$choice'>"; for($i=0; $i<=$avilable; $i++) { echo "<option value='$i' >$i</option>"; } echo "<td >$price</td> </tr>"; } ?> <input type="submit" value="Submit" name="submit"> PHP: -John
thanx John for ur help but it didn't work for me Should i put isset($_POST['submit']) here or in the page that i specify in the form ?? Sorry again