lanceox Posted May 13, 2011 Share Posted May 13, 2011 Hi guys, i have a select box which has been populated with values from the database however i would like to be able to select the value from the select box and change the qty. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>stock manager</title> </head> <body> <?php $stockqty =&$_POST['stock_qty1']; ?> <center> <table> <td> <table> <td> <form action='stockview.php' method='POST'> Please Enter a Stock Name and Stock Value <table> <tr> <td> Stock Name: </td> <td> <input name="stock_name" type="text" /><BR /> </td> </tr> <tr> <td> Stock Qty: </td> <td> <input name="stock_qty" type="text" /> </td> </tr> </table> <input name="submit" type="submit" value="Add New Stock Items" /> </form> </td> </table> </td> <td> <table> <td> <form action='stockmanager.php' method='POST' enctype="multipart/form-data"> Please Select from the list the item you wish to update <table> <tr> <td> Stock Name: </td> <td> <?php $connect = mysql_connect("localhost","root", "") or die ("Couldn't Connect!"); mysql_select_db("stock", $connect) or die("Couldn't find db"); // select database $query=("SELECT id, stockname FROM stocks"); $result = mysql_query ($query); echo "<select name=stock value=''>Edit Stock QTY</option>"; while($nt=mysql_fetch_array($result)) { //Array or records stored in $nt echo "<option value=$nt[id]>$nt[stockname]</option>"; /* Option values are added by looping through the array */ } $queryreg = mysql_query("SELECT * FROM stocks WHERE stockqty='$stockqty'"); $numrows = mysql_num_rows($queryreg); $update = mysql_query("UPDATE stocks SET stockqty='$stockqty' WHERE stockname = '$stockname'"); echo("Its updated"); ?> </td> </tr> <tr> <td> Stock Qty: </td> <td> <input name="stock_qty1" type="text" /> </td> </tr> </table> <input name="submit" type="submit" value="Update stock items" /> </form> </td> </table> </td> </table> </center> </body> </html> Any help would be greatly appreciated... ive been working on this for a while and cant seem to find the answer. Thanks Lance Quote Link to comment https://forums.phpfreaks.com/topic/236350-how-to-update-values-in-a-database/ Share on other sites More sharing options...
spiderwell Posted May 13, 2011 Share Posted May 13, 2011 if your echo out your sql statements by passing them to a variable, you can see what is or isnt happening Quote Link to comment https://forums.phpfreaks.com/topic/236350-how-to-update-values-in-a-database/#findComment-1215155 Share on other sites More sharing options...
lanceox Posted May 13, 2011 Author Share Posted May 13, 2011 Everything works fine and the select box appears and i can choose options from the database, however when i enter a new quantity the values are not modified.... So is there something wrong with the actual insert statements Im not sure how to choose the value from the select field. Hope this makes more sense Thanks Lance Quote Link to comment https://forums.phpfreaks.com/topic/236350-how-to-update-values-in-a-database/#findComment-1215181 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.