Hi,
I have a mysql database for stock records in the pub I work in. The code below displays the list of items and sizes, what I need is to be able to update several rows by subtracting the number in the qty column from the bal column in the database when I hit the go button. I thought I had it but it doesn't work, any suggestions welcome!
dbase
CREATE TABLE IF NOT EXISTS `levels` (
`itemsize` varchar(55) NOT NULL,
`item` varchar(55) NOT NULL,
`size` varchar(5) DEFAULT NULL,
`code` varchar(10) NOT NULL,
`bal` varchar(4) NOT NULL,
`max` varchar(4) NOT NULL,
`min` varchar(4) NOT NULL,
`supp` varchar(55) DEFAULT ' ---',
UNIQUE KEY `ident` (`itemsize`)
)
<?php
mysql_connect("localhost","root","corrupt") or die("cannot connect");
mysql_select_db("stock") or die("cannot select db");
$res=mysql_query("SELECT * FROM levels ORDER BY item ASC ");
echo "<html>
<head>
<title>Stock Control</title>
<link rel='stylesheet' type='text/css' href='style.css'>
</head>
<body>";
echo "<div class='top'></div>
<div class='mid'>
<table width='800' border='0' class='order' align='center'><form name='update' action='$self' method='post'>
<tr class='order'>
<td class='heading' align='center' colspan='8'>Update List</td>
</tr>
<tr>
<td class='sub'>Item</td><td class='sub'>Qty</td><td class='sub'>Max Qty</td><td class='sub'>Min Qty</td>
</tr><tr><td colspan='10'><hr color='#000000'></td></tr>";
$count=mysql_num_rows($res);
while($row=mysql_fetch_array($res)) {
echo "<tr>";
$item=$row['itemsize'];
$size=$row['size'];
$bal=$row['bal'];
$min=$row['min'];
$max=$row['max'];
$sup=$row['supp'];
echo "<td class='grid'><input type='text' name='part' value='".$item."'></td><td class='grid'><input type='text' name='upd'></td><td class='grid'>".$max."</td><td class='grid'>".$min."</td>";
}
echo "</tr><tr>
<td colspan='10' align='right'><input type='submit' name='go' value='Go'></form>
</table>";
echo "</div><div class='bottom'><br></div>";
echo "</body>";
echo "</html>";
if(isset ($_POST['go'])) {
$new=$_POST['upd'];
$item=$_POST['part'];
for($i=0; $i<$count; $i++) {
$z=mysql_query("UPDATE levels SET bal=bal-'$new[$i]' WHERE itemsize= '$item[$i]'");
$result=mysql_query($z);
}
}
if($result) {
header('location:list.php');
}
?>