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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.