Hi...All...
I need some advice regarding inserting data from a form to a mysql table. I am unable to get the data posted into the table.
Following are my two files :
First file generates dynamic input fields and stores in a array (i hope my syntax is correct). Then upon submit i want the values to be inserted into the table.
firstfile.php
<form name="items" method="get">
<input name="number" type="text" id="number" size="6">
</p>
<input type="submit" name="Submit" value="Submit">
</form>
<?
echo "<table>";
echo "<tr>";
echo "<td width=90> Item No </td>";
echo "<td width=310> Description </td>";
echo "</tr>";
echo "</table>";
?>
<?
echo "<form name=insertitem method=post action='secondfile.php'>";
echo "<table>";
$number=$_GET["number"];
if ($number>15)
{
$number=15;
echo "<font color=red>You are allowed to enter maximum 15 items at a time </font>";
}
else
{
$number=$_GET["number"];
}
for ($i=1; $i<=$number; $i++)
{
echo "<tr>";
echo "<td> <input type=text name=itemno[$i] size=5> </td>" ;
echo "<td> <input type=text name=description[$i] size=50> </td>" ;
echo "</tr>";
}
echo "</table>";
echo "<input type=submit name=submit value=Submit>";
echo "</form>";
?>
</body>
secondfile.php
<?
include("link.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$itemnos = $_POST['itemno'];
$descriptions = $_POST['description'];
$query = "INSERT INTO table_name VALUES('','$itemnos','$descriptions')";
mysql_query($query);
mysql_close();
?>
All suggestions are appreciated.
Thanks in advance.