Jump to content

[SOLVED] help with multiple checkboxes


mike1313

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

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.