Jump to content

Updating Multiple Input Boxes


medj

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/110019-updating-multiple-input-boxes/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.