Drauka Posted May 10, 2007 Share Posted May 10, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/50810-solved-updating-multiple-entries-at-once/ Share on other sites More sharing options...
fenway Posted May 10, 2007 Share Posted May 10, 2007 Could you post the $sql_stat that you've echoed? Quote Link to comment https://forums.phpfreaks.com/topic/50810-solved-updating-multiple-entries-at-once/#findComment-249845 Share on other sites More sharing options...
Drauka Posted May 10, 2007 Author Share Posted May 10, 2007 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 = '' Quote Link to comment https://forums.phpfreaks.com/topic/50810-solved-updating-multiple-entries-at-once/#findComment-249849 Share on other sites More sharing options...
fenway Posted May 10, 2007 Share Posted May 10, 2007 Well, that's your problem... your hash isn't being populated the way you think it is. Quote Link to comment https://forums.phpfreaks.com/topic/50810-solved-updating-multiple-entries-at-once/#findComment-249851 Share on other sites More sharing options...
Drauka Posted May 10, 2007 Author Share Posted May 10, 2007 So, could you maybe give me a hint how to change that, please? Quote Link to comment https://forums.phpfreaks.com/topic/50810-solved-updating-multiple-entries-at-once/#findComment-249867 Share on other sites More sharing options...
fenway Posted May 10, 2007 Share Posted May 10, 2007 That's a PHP issue... post the raw HTML being produced, I want to make sure that the UIDs come through correct. Quote Link to comment https://forums.phpfreaks.com/topic/50810-solved-updating-multiple-entries-at-once/#findComment-249886 Share on other sites More sharing options...
Drauka Posted May 11, 2007 Author Share Posted May 11, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/50810-solved-updating-multiple-entries-at-once/#findComment-250365 Share on other sites More sharing options...
fenway Posted May 11, 2007 Share Posted May 11, 2007 I see lots of elemetn with the same name. Quote Link to comment https://forums.phpfreaks.com/topic/50810-solved-updating-multiple-entries-at-once/#findComment-250645 Share on other sites More sharing options...
Drauka Posted May 16, 2007 Author Share Posted May 16, 2007 I just wanted to say a big THANK YOU! It works now Quote Link to comment https://forums.phpfreaks.com/topic/50810-solved-updating-multiple-entries-at-once/#findComment-254394 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.