Jump to content

[SOLVED] Posting and then using multiple values with a form?


spiceydog

Recommended Posts

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>

Archived

This topic is now archived and is closed to further replies.

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