Jump to content

Recommended Posts

So I'm working on my in-game mail system and when the user is in the inbox they can click a checkbox to select/deselect all messages then delete them. But the problem I have is since I'm using a while statement the checkboxes appear in the while so that a checkbox can be displayed for each record. How would I go about deleting the ones that are clicked so I can delete them?

 

echo "<form name=mform>
<table align=center>
<tr>
<td><b>Message</b>
</td>
<td width=25%> </td>
<td width=25%><b>From</b>
</td>
<td width=25%><b>Sent</b>
</td>
<td>Check all?</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td><input type=checkbox name=checkall onclick=\"checkUncheckAll(this);\">
</td>
</tr>";

while ($q4 = mysql_fetch_array($query4)){

$msg = substr($q4[message], 0, 24);
$msg2 = strlen($q4[message]);
if($msg2 > "24"){ $msg3 = "..."; }
$query5 = mysql_query("SELECT * FROM `players` WHERE `from`='$q4[id]'");
$q5 = mysql_fetch_array($query5);
echo "<tr>
<td width=25%><a href=mail.php?per=view&vid=$q4[id]>$q4[title]</a><br>$msg<b>$msg3</b><br><hr width=100%>
</td>
<td width=25%>
</td>
<td width=25%>$q5[username]
</td>
<td width=25%>$q4[date]</td>
<td><input type=checkbox name=del>
</tr>";
}
echo "</form></table>";

Link to comment
https://forums.phpfreaks.com/topic/82973-solved-help-with-multiple-checkboxes/
Share on other sites

Name the checkboxes with "[]" at the end of the name so they are posted as an array.

Give the c/box a value of the record id to be deleted if checked

 

<?php
echo "<input type=checkbox name='del[]' value='$recordID'>";
?>

 

When form is submitted

<?php
$deleteList = join ("','", $_GET['del']);
mysql_query ("DELETE FROM tablename WHERE id IN ('$deleteList')");

One more thing how would I check when that same code was submitted whether theres wasnt any checkboxes checked.

 

because normally it would be

 

<?php
if($_POST[name] == "off"){
echo "NOT CHECKED";
}
?>

 

But that doesnt seem to work

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.