help with updating a mysql table using a php form
Posted: Tue Jun 28, 2005 11:25 am
inv.php has a form that posts to itself attempting to update table inv, where category 'no' is the auto-increment primary category. The problem I am having is getting the looped form to post any row past the first row. I am a little familiar with creating arrays, but I don't know how to make an array that accounts for multiple random rows from a mysql table. There are about 500 rows in this table, and I am able to view them all in this form, but I can't update them. Does anyone have any suggestions?
Here is the relevant code from inv.php:[/i]
Here is the relevant code from inv.php:
Code: Select all
if(isset($_POST['update']))
{
$itemno = $_POST['itemno'];
$lotshow = $_POST['lotshow'];
$qty = $_POST['qty'];
$size = $_POST['size'];
$conc = $_POST['conc'];
$vol = $_POST['vol'];
$location = $_POST['location'];
$notes = $_POST['notes'];
$no = $_POST['no'];
require_once('mysqladmin.php');
$query = "UPDATE inv SET itemno='$itemno', lotshow='$lotshow',
qty='$qty', size='$size', conc='$conc', vol='$vol',
location='$location', notes='$notes' WHERE no='$no'";
$result = mysql_query($query);
}
require_once('mysqladmin.php');
$query = "SELECT * FROM inv WHERE location != ' ' ORDER BY location";
$result = mysql_query ($query);
?>
<form action=inv.php method=post>
<center><input type=submit name=update value=Update></center>
<table border=1 bordercolor=000000 cellpadding=0 cellspacing=0>
<tr bgcolor=00ff00><td>Item</td>
<td>Lot</td>
<td>Qty.</td>
<td>Size</td>
<td>Conc.</td>
<td>Vol.</td>
<td>Location</td>
<td>notes</td>
</tr>
<?php
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC))
{
?><input type=hidden name=no value="<?php echo "$row[no]";?>">
<tr><td><input type=text name=itemno value="<?php echo "$row[itemno]";?>"></td>
<td><input type=text name=lotshow value="<?php echo "$row[lotshow]";?>" size=7></td>
<td><input type=text name=qty value="<?php echo "$row[qty]";?>" size=3></td>
<td><input type=text name=size value="<?php echo "$row[size]";?>" size=5></td>
<td><input type=text name=conc value="<?php echo "$row[conc]";?>" size=6></td>
<td><input type=text name=vol value="<?php echo "$row[vol]";?>" size=5></td>
<td><input type=text name=location value="<?php echo "$row[location]";?>" size=7></td>
<td><input type=text name=notes value="<?php echo "$row[notes]";?>"size=25></td>
</tr>
</form>
<?php
}