spiceydog Posted July 26, 2008 Share Posted July 26, 2008 i got a php/mysql script that is working as a messaging system. the problem is that the delete isnt working correctly. next to each message is a check box with a "delete messages" submit button at the bottom. when the form is submitted it does some mysql queries and sets a mysql value. all of the mysql works but the problem is getting it to recognize each posted value seperately because currently it just deletes the first of the checked boxes. Here is my current code: <?php if(isset($_POST['submit'])) { $mid = $_POST['delete']; foreach ($mid as $value) { $result = mysql_query("SELECT * FROM inbox WHERE mid = '$value' AND reply = 0"); while($row = mysql_fetch_array($result)){ $subject = $row['subject']; $date = $row['date']; $id = $row['id']; $message = $row['message']; $delto = $row['delto']; $delfrom = $row['delfrom']; $fromwho = $row['fromwho']; $towho = $row['towho']; if ($fromwho == $username) { mysql_query("UPDATE inbox SET delfrom = 1 WHERE mid = '$value'"); header("Location: inbox.php"); } if ($towho == $username) { mysql_query("UPDATE inbox SET delto = 1 WHERE mid = '$value'"); header("Location: inbox.php"); } } } } ?> <form action="inbox.php" method="post"> <?php $query = "SELECT * FROM inbox WHERE towho ='$username' AND delto != 1 GROUP BY subject ORDER BY id DESC" or die(mysql_error()); $result = mysql_query($query) or die("Couldn't execute query because: ".mysql_error()); while($row = mysql_fetch_array($result)){ $subject = $row['subject']; $from = $row['fromwho']; $date = $row['date']; $mid = $row['mid']; { ?> <input type="checkbox" value="<?php print "$mid"; ?>" name="delete" />From: <?php print "$from"; ?> - <a href="message.php?mid=<?php print "$mid"; ?>"><?php print "$subject"; ?></a> | Sent <?php print "$date"; ?> = <a href="delmessage.php?mid=<?php print "$mid"; ?>">Delete Message</a><br /> <?php } } ?> <input type="submit" value="Delete Messages" name="submit" /> </form> Link to comment https://forums.phpfreaks.com/topic/116690-solved-posting-and-then-using-multiple-values-with-a-form/ Share on other sites More sharing options...
spiceydog Posted July 26, 2008 Author Share Posted July 26, 2008 FIXED!! i needed to change the name="delete" to name="delete[]" so it would be treated as an array Link to comment https://forums.phpfreaks.com/topic/116690-solved-posting-and-then-using-multiple-values-with-a-form/#findComment-600008 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.