Hi, I'm very new to these forums and php alike. I've been working on this bit of code for weeks now. I've written numerous versions and made endless revisions; trying pieces from many similiar source and well, it's still not quite working out for me.
The form I've been trying to finish will have multiple rows. The user will input values specific to each row, but I'm trying to make it so that each row is synonymous with each other in regard to the database table. Like an order form, an inventory form, or a roster. I'd really like to make this code work out because I can think of numerous applications for it's use. I'm sure others could use it for even more.
So, as you see; the html code represents the table that contains the form. Currently, I only have five of these rows in the form, but would like for anybody using the code to be able to add in code for as many rows in the table as needed.
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<FORM action="post_multiple.php" method="POST">
<table width="80%" border="1">
<tr>
<td>Vendor</td>
<td>Item Description</td>
<td>Quantity</td>
<td>Price</td>
</tr>
<tr>
<td><select name="vendor" id="vendor" >
<option value="other1">other1</option>
<option value="other2">other1</option>
<option value="other3">other3</option>
<option value="other4">other4</option>
<option value="other5">other5</option>
</select></td>
<td><input name="description" type="text" id="description" size="50" /></td>
<td><input name="quantity" type="text" id="quantity" size="50" /></td>
<td><input name="price" type="text" id="price" size="50" /></td>
</tr>
<tr>
<td><select name="vendor" id="vendor">
<option value="other1">other1</option>
<option value="other2">other1</option>
<option value="other3">other3</option>
<option value="other4">other4</option>
<option value="other5">other5</option>
</select></td>
<td><input name="description" type="text" id="description" size="50" /></td>
<td><input name="quantity" type="text" id="quantity" size="50" /></td>
<td><input name="price" type="text" id="price" size="50" /></td>
</tr>
<tr>
<td><select name="vendor" id="vendor">
<option value="other1">other1</option>
<option value="other2">other1</option>
<option value="other3">other3</option>
<option value="other4">other4</option>
<option value="other5">other5</option>
</select></td>
<td><input name="description" type="text" id="description" size="50" /></td>
<td><input name="quantity" type="text" id="quantity" size="50" /></td>
<td><input name="price" type="text" id="price" size="50" /></td>
</tr>
<tr>
<td><select name="vendor" id="vendor">
<option value="other1">other1</option>
<option value="other2">other1</option>
<option value="other3">other3</option>
<option value="other4">other4</option>
<option value="other5">other5</option>
</select></td>
<td><input name="description" type="text" id="description" size="50" /></td>
<td><input name="quantity" type="text" id="quantity" size="50" /></td>
<td><input name="price" type="text" id="price" size="50" /></td>
</tr>
<tr>
<td><select name="vendor" id="vendor">
<option value="other1">other1</option>
<option value="other2">other1</option>
<option value="other3">other3</option>
<option value="other4">other4</option>
<option value="other5">other5</option>
</select></td>
<td><input name="description" type="text" id="description" size="50" /></td>
<td><input name="quantity" type="text" id="quantity" size="50" /></td>
<td><input name="price" type="text" id="price" size="50" /></td>
</tr>
<tr>
<td><select name="vendor" id="vendor">
<option value="other1">other1</option>
<option value="other2">other1</option>
<option value="other3">other3</option>
<option value="other4">other4</option>
<option value="other5">other5</option>
</select></td>
<td><input name="description" type="text" id="description" size="50" /></td>
<td><input name="quantity" type="text" id="quantity" size="50" /></td>
<td><input name="price" type="text" id="price" size="50" /></td>
</tr>
</table>
<input type="submit" name="Submit" value="Submit" />
</FORM>
</body>
</html>
In the php script I've tried using the count, loop, if, several others functions to try to get it to insert all the completed rows from the form into the table but just can't seem to get it to work out. Anyways, here's a representation of what i'd like to achieve. Not necessarily the code I've written trying to accomplish this, I'd have to upload a book if that were the case.
<?php
ini_set('display_errors','On');
error_reporting(E_ALL);
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="password"; // Mysql password
$db_name="testing"; // Database name
$tbl_name="test_multiple"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
//declarations
$vendor = $_POST['vendor'];
$description = $_POST['description'];
$quantity = $_POST['quantity'];
$price = $_POST['price'];
// Check if button name "Submit" is active, do this
$sql1="INSERT INTO $tbl_name (vendor, description, quantity, price) VALUES ('".$vendor."', '".$description."', '".$quantity."', '".$price."')";
$result1=mysql_query($sql1);
mysql_close();
?>
If anybody can suggest where I need to go with that, that would be great. Like I said above, I've tried about everything I could find any reason to from forum threads I had found in google searches and whatnot. Also, if there is a good article, link or tutorial that would address this that anybody knows about that would be great. However, I'm not looking for a link to a product or plugin that will do this stuff for me. I'm trying to get halfway decent at php and would like to have working code for myself to build upon, modify, and learn from. Any help is greatly appreciated!!!!