manouche Posted March 3, 2010 Share Posted March 3, 2010 I have a database that I want to query and be able to modify one of the fields. This one field will display as a drop down select menu. I want to be able to modify that field contents by selecting a different choice from the drop down and modifying one or more records when I click on the 'Modify' button. I have been able to query the database and display the results, including the drop down menu. The field to be modified is named 'status'. When I click on the 'Modify' button, it appears to be doing what I expect, as it eventually redirects back to the search page. However, the records are not being updated. Ideally, I'd like to only be updating the records that have changed. Here is how I populate the drop down menu. It may be messy and too much code, but I needed to be able to display the 'selected' value in the drop down for each displayed record. $options = array("", "", "", "", "", "", "", "", "", "", "", "", "", "", ""); //Make x amount of blank fields, where x is the amount of options if($status == "already cataloged"){ $options[0] = "selected"; }elseif($status == 'Archived'){ $options[1] = "selected"; }elseif($status == "Contacted publisher"){ $options[2] = "selected='selected'"; }elseif($status == "Discuss"){ $options[3] = "selected='selected'"; }elseif($status == "Investigate"){ $options[4] = "selected='selected'"; }elseif($status == "Multipart"){ $options[5] = "selected='selected'"; }elseif($status == "New"){ $options[6] = "selected='selected'"; }elseif($status == "Reject"){ $options[7] = "selected='selected'"; }elseif($status == "Serials (also in paper)"){ $options[8] = "selected='selected'"; }elseif($status == "Serials (online only)"){ $options[9] = "selected='selected'"; }elseif($status == "Serial issue to archive"){ $options[10] = "selected='selected'"; }elseif($status == "Switched to online"){ $options[11] = "selected='selected'"; }elseif($status == "To be archived"){ $options[12] = "selected='selected'"; }elseif($status == "To be converted and archived"){ $options[13] = "selected='selected'"; }elseif($status == "Waiting for paper"){ $options[14] = "selected='selected'"; } ?> <SELECT> <option value ="already cataloged" <?php echo $options[0]; ?>>Already cataloged</option> <option value ="archived" <?php echo $options[1]; ?>>Archived</option> <option value ="contacted publisher" <?php echo $options[2]; ?>>Contacted publisher</option> <option value ="discuss" <?php echo $options[3]; ?>>Discuss</option> <option value ="investigate" <?php echo $options[4]; ?>>Investigate</option> <option value ="multipart" <?php echo $options[5]; ?>>Multipart</option> <option value ="new" <?php echo $options[6]; ?>>New</option> <option value ="reject" <?php echo $options[7]; ?>>Reject</option> <option value ="serials (also in paper)" <?php echo $options[8]; ?>>Serials (also in paper)</option> <option value ="serials (online only)" <?php echo $options[9]; ?>>Serials (online only)</option> <option value ="serial issue to archive" <?php echo $options[10]; ?>>Serial issue to archive</option> <option value ="switched to online" <?php echo $options[11]; ?>>Switched to online</option> <option value ="to be archived" <?php echo $options[12]; ?>>To be archived</option> <option value ="to be converted and archived" <?php echo $options[13]; ?>>To be converted and archived</option> <option value ="waiting for paper" <?php echo $options[14]; ?>>Waiting for paper</option> <input type="submit" name = "modify" value = "modify"> I then test to see if the 'modify' button has been clicked: <?php if($_POST['modify']){ $sql1="UPDATE documents SET status='$status' WHERE id='$id' "; $result1=mysql_query($sql1); } if($result1){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=NEWindex.php\">"; } ?> I think I am getting hung up with the code that updates. Can someone provide some clarify to all of this? Thank you kindly. I have worked on this for a good long time and can't seem to get it. Link to comment https://forums.phpfreaks.com/topic/194068-updating-multiple-records-with-form-on-submit/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.