Jump to content

Recommended Posts

Hi all.

 

I really hope you can help me with this, but I'm really stuck and don't really know what I've done wrong.

Situation is as follows:

I have a list of entries from a DB. Each of those entries has a field 'status'. What I want to do now is change the status for multiple rows with just one submit.

What I have is this:

 

if (isset($_POST["updaten"])) {

   foreach ($_POST['ID'] as $key => $values) {

   	 $ID = $_POST['ID'][$key];
   	 $status_change = $_POST['status'][$key];
          $sql_stat = "
		UPDATE rma
	SET status = '".$status_change[$key]."'
		WHERE id = '".$ID[$key]."'";
          echo $sql_stat.'<br>';
          mysql_query($sql_stat) or die (mysql_error());
  }
}

 

and in the form there is this:

 

echo '<input type="hidden" name="ID[]" value="'.$row[id].'"></input>';
echo '<select name="status[]">';
echo    "<option value=\"1\"";
       	if ($status == '1') {echo " selected=\"selected\"";}
echo ">Status 1</option>";
echo "<option value=\"2\"";
      	if ($status == '2') {echo " selected=\"selected\"";}
echo ">Status 3</option>";
echo "<option value=\"3\"";
      	if ($status == '3') {echo " selected=\"selected\"";}
echo ">Status 3</option>";

^^Sorry the html part still looks a little crappy...

 

No matter how many fields I change in the list then, only the first entry changes. So it works for the first entry, not for the rest.

Maybe someone can help me with this?

 

Thank you very much!

Best regards

Alex

Link to comment
https://forums.phpfreaks.com/topic/50810-solved-updating-multiple-entries-at-once/
Share on other sites

I've got 6 entries in the list and it echos this:

 

UPDATE rma SET status = '1' WHERE id = '1'

UPDATE rma SET status = '' WHERE id = ''

UPDATE rma SET status = '' WHERE id = ''

UPDATE rma SET status = '' WHERE id = ''

UPDATE rma SET status = '' WHERE id = ''

UPDATE rma SET status = '' WHERE id = ''

HI again.

 

Here' the HTML:

 

<html>
  <head>
<title>Verwaltung DB</title>
<meta name="author" content="alex">
</head>
<style type="text/css" title="currentStyle" media="screen">
  @import "css/style.css";
</style>
<body>
<p><a href="new.php">neuen Fall eintragen</a></p>

		UPDATE rma
	SET status = '3'
		WHERE id = '1'<br>
		UPDATE rma
	SET status = ''
		WHERE id = ''<br>

		UPDATE rma
	SET status = ''
		WHERE id = ''<br>
		UPDATE rma
	SET status = ''
		WHERE id = ''<br>
		UPDATE rma
	SET status = ''
		WHERE id = ''<br>
		UPDATE rma
	SET status = ''
		WHERE id = ''<br>             <form action="index.php" method="post">
             <table width="750" border="0" cellspacing="0" cellpadding="0">
             <tr>

             <td bgcolor="#555555">
             <table width="100%" cellspacing="1" cellpadding="1" border="0">
	<tr>
          <td bgcolor="#555555"><b><a href="index.php?sort=rma_no">DB RMA#</a></b></td>
          <td bgcolor="#555555"><b>Name</b></td>
          <td bgcolor="#555555"><b>S/N</b></td>
          <td bgcolor="#555555"><b>SKU</b></td>

          <td bgcolor="#555555"><b>P/N</b></td>
                   <td bgcolor="#555555"><b><a href="index.php?sort=status">Status</a></b>  </td>
                   <td bgcolor="#555555"><b>Details</b></td>
         </tr>
                  <tr>
                    <td bgcolor="#034A9A">
                     <input type="hidden" name="ID[]" value="1"></input>
                     <a href="details.php?id=1">DB000001</a>
                    </td>
                    <td bgcolor="#034A9A"><a href="details.php?id=1">Name 1</a></td>
                    <td bgcolor="#034A9A">A054600149081</td>
                    <td bgcolor="#034A9A">sku1</td>
                    <td bgcolor="#034A9A">pn1</td>
                    <td bgcolor="#034A9A">
                      <select name="status[]">
                        <option value="1">Option 1</option>
                        <option value="2">Option 2</option>
                        <option value="3" selected="selected">Option 3</option>
                        <option value="4">Option 4</option>
                        <option value="5">Option 5</option>
                        <option value="6">Option 6</option>
                        <option value="7">Option 7</option>
                        <option value="8">Option 8</option>
                        <option value="9">Option 9</option>
                       </select>
                     </td>
                     <td bgcolor="#034A9A"><a href="details.php?id=1">Details</a></td> 
                  </tr>
                  <tr>
                   <td bgcolor="#034A9A"><input type="hidden" name="ID[]" value="2"></input><a href="details.php?id=2">DB000002</a></td>
                   <td bgcolor="#034A9A"><a href="details.php?id=2">Name 2</a></td>
                   <td bgcolor="#034A9A">A045100147912</td>
                   <td bgcolor="#034A9A">fehlt</td>
                   <td bgcolor="#034A9A">99-LC00-1D-FS</td>
                   <td bgcolor="#034A9A">
                      <select name="status[]">
                        <option value="1">Option 1</option>
                        <option value="2">Option 2</option>
                        <option value="3">Option 3</option>
                        <option value="4">Option 4</option>
                        <option value="5">Option 5</option>
                        <option value="6" selected="selected">Option 6</option>
                        <option value="7">Option 7</option>
                        <option value="8">Option 8</option>
                        <option value="9">Option 9</option>
                      </select>
                    </td>
                    <td bgcolor="#034A9A"><a href="details.php?id=2">Details</a></td>
                   </tr>
                   <tr>
                    <td bgcolor="#034A9A"><input type="hidden" name="ID[]" value="3"></input><a href="details.php?id=3">DB000003</a></td>
                    <td bgcolor="#034A9A"><a href="details.php?id=3">Name 3 </a></td>
                    <td bgcolor="#034A9A">A060100012135</td>
                    <td bgcolor="#034A9A">fehlt</td>
                    <td bgcolor="#034A9A">fehlt</td>
                    <td bgcolor="#034A9A">
                       <select name="status[]">
                        <option value="1">Option 1</option>
                        <option value="2">Option 2</option>
                        <option value="3">Option 3</option>
                        <option value="4">Option 4</option>
                        <option value="5">Option 5</option>
                        <option value="6">Option 6</option>
                        <option value="7" selected="selected">Option 7</option>
                        <option value="8">Option 8</option>
                        <option value="9">Option 9</option>
                       </select>
                     </td>
                     <td bgcolor="#034A9A"><a href="details.php?id=3">Details</a></td>
                    </tr>
                    <tr>
                     <td bgcolor="#034A9A"><input type="hidden" name="ID[]" value="4"></input><a href="details.php?id=4">DB000004</a></td>
                     <td bgcolor="#034A9A"><a href="details.php?id=4"></a></td>
                     <td bgcolor="#034A9A"></td>
                     <td bgcolor="#034A9A"></td>
                     <td bgcolor="#034A9A"></td>
                     <td bgcolor="#034A9A">
                      <select name="status[]">
                        <option value="1" selected="selected">Option 1</option>
                        <option value="2">Option 2</option>
                        <option value="3">Option 3</option>
                        <option value="4">Option 4</option>
                        <option value="5">Option 5</option>
                        <option value="6">Option 6</option>
                        <option value="7">Option 7</option>
                        <option value="8">Option 8</option>
                        <option value="9">Option 9</option>
                       </select>
                      </td>
                      <td bgcolor="#034A9A"><a href="details.php?id=4">Details</a></td>
                    </tr>
                  </table>
                 </td>
               </tr>
            </table>
           <input type="submit" name="updaten" value="Save" style="margin-left: 15px;""></input>

       </form>
   </body>
</html>

 

I deleted the last entries, because it's all the same and it would just take up space here.

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.