medj Posted June 13, 2008 Share Posted June 13, 2008 I have a column called "Stock" of one of my tables which has an integer value. I have many rows in my database and what I want to do is create a page which will give an input box with all the stock values for me to be able to update. Well in fact, I have already did this much, in terms of showing the input box with the value of the stock being displayed inside. What I want is a "Update All" Button at the bottom when clicked will update all stock values that I change on the page. Any help is greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/110019-updating-multiple-input-boxes/ Share on other sites More sharing options...
fenway Posted June 13, 2008 Share Posted June 13, 2008 This is more of a php question, really.... Quote Link to comment https://forums.phpfreaks.com/topic/110019-updating-multiple-input-boxes/#findComment-564777 Share on other sites More sharing options...
medj Posted June 13, 2008 Author Share Posted June 13, 2008 But somehow I need a button at the end that will UPDATE all values of any rows I happen to edit. Quote Link to comment https://forums.phpfreaks.com/topic/110019-updating-multiple-input-boxes/#findComment-564849 Share on other sites More sharing options...
fenway Posted June 13, 2008 Share Posted June 13, 2008 But somehow I need a button at the end that will UPDATE all values of any rows I happen to edit. Yes, and that "button" triggers a form action that will get processed by PHP. Quote Link to comment https://forums.phpfreaks.com/topic/110019-updating-multiple-input-boxes/#findComment-564904 Share on other sites More sharing options...
medj Posted June 13, 2008 Author Share Posted June 13, 2008 Okay, I have been working on this for the past 2 hours and I think I actually was able to get pretty far. It is still not working though, I was hoping someone could take a look at my code below and let me know what is wrong. I will paste some of the important parts. <form name="form1" method="post" action="display.php"> ... while ($rows = mysql_fetch_array($match_query)) { $id[] = $rows['part_num']; ... <td class="<? echo $color; ?>"><input name="stock[]" type="text" id="stock" size="5" value="<? echo $rows['stock']; ?>"></td> ... <input type="submit" name="Update" value="Update"> ... if (isset($_POST['Update'])) { for($i=0;$i<$count;$i++){ print $id[$i]; $update_stock = mysql_query( "UPDATE components SET stock='$stock[$i]' WHERE part_num='$id[$i]'" ) or die("SELECT Error: ".mysql_error()); } } if($update_stock){ header("location:display.php"); } mysql_close(); I want to be able to change as many stock values as I want and then click update at the bottom in which the page will be refreshed with the new values and the message "Database updated" or something like that. You can see my results by clicking http://eldoled.blankevolution.com Quote Link to comment https://forums.phpfreaks.com/topic/110019-updating-multiple-input-boxes/#findComment-564962 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.