Update Stock Form Problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mmc01ms
Forum Commoner
Posts: 97
Joined: Wed Dec 01, 2004 3:33 am
Location: Nottingham, UK

Update Stock Form Problems

Post by mmc01ms »

Code: Select all

<? 

function updatestockform()
		{
			$link_id = db_connect();
			
			$query = "select cat_no, title, stock_level from vinyls";
			
			$result = mysql_query($query, $link_id) or die(mysql_error());
			
			if(!result)
			{
				echo 'No Stock Returned.';
				exit;
			}else
			
			$list ="<center><table border="1" cellpadding="2" bgcolor="#7b9815" bordercolor="#d2e982">";
			$list.="<form align="center" name="updatestockform" method="post" action="stock.php?action=updatestock">";
			$list.="<tr><th><div align="left"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Catalogue Number</div></font></th>";
			$list.="<th><div align="left"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Title</div></font></th>";
			$list.="<th><div align="left"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Qty</div></font></th>";
			$list.="<th><div align="left"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Add</div></font></th></tr></div></font>";

			while($row = mysql_fetch_array($result))
			{
				$list.= "<tr>";
				$list.= "<td><div align="left"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">".$row["cat_no"]."</div></font></td>";
				$list.= "<td><div align="left"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">".$row["title"]."</div></font></td>";
				$list.= "<td><div align="left"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">".$row["stock_level"]."</div></font></td>";
				$list.= "<td width="10"><div align="left"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><input name="qty" type= "text" maxlength="3" id="qty"></div></font></td>";
				$list.= "<td><input name="qtyselected" type="radio"></td>";
				$list.=	"<td><input type="submit" value="Update"></td>";
				
				
			}
			$list.= "</table></center>";
			
			echo($list);
			
		}
		
		function updatestock()
		{
			$cat_no = $_POST['cat_no'];
			$title = $_POST['title'];
			$stock_level = $_POST['stock_level'];
			$qty = $_POST['qty'];
			$new_stock_level = (($_POST['qty'] )+ ($_POST['stock_level']));
			
			
			$link_id = db_connect();
			
			$query = "update vinyls 
						set stock_level = '$new_stock_level'
						where cat_no = '$cat_no'";
				
				$result = mysql_query($query, $link_id) or die(mysql_error());	
			
			if($result)
			{
				echo 'Succesfully Entered';
			}
			
			updatestockform();
		}
		
		
		
		
		
		
		
		
		
		
		
	?>
I've created a form where i can update my stock level by adding the existing qty to the new qty and getting our new stock_level qty. However it doesn't seem to do this, in fact it states that the sql statement was succesful however when i check in mysql it hasn't done the statement?Any ideas?Any other methods for doing this? I've tried the $new_stock_level varible with and without brackets round the addition and it don't make any difference.
Post Reply