i can't update my stock levels?

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

i can't update my stock levels?

Post by mmc01ms »

I'm having problems writing a function to update my stock level for an item. I enter a value for the qty i want to add to the stock file however it doesn't carry this out. code for the form and function are below any ideas?

Code: Select all

<? 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();
		}
?>

Code: Select all

<?    function updatestockform()
		{
			$link_id = db_connect();
			
			$query = "select cat_no, title, artist_id, 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">Artist</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["artist_id"]."</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);
			
		}?>
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

why not just do this:

Code: Select all

query = "update vinyls 
                        set stock_level = stock_level + ".$_POST['qty']." 
                        where cat_no = '$cat_no'";
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Where it says: $new_stock_level = (($_POST['qty']) + ($_POST['stock_level']));

Write:

Code: Select all

$new_stock_level = $HTTP_POST_VARS['qty'] + $HTTP_POST_VARS['stock_level'];
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

also echo out the sql before execution and try it thru the gui tool of your choice for your db
Post Reply