Jump to content

Archived

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

legohead6

deleting variable number of checkboxes

Recommended Posts

Hi, This is a private message inbox from a forum...i want so that when you check the box on a message it deletes it!

Heres the code:

[code]<?PHP
session_start();
echo "<p align=center><font size=6>Inbox</font></p>";
echo "<p align=center><a href='sendpm.php'>Send a Message</a><br><br></p>";
$username="*********";
$password="*********";
$database="*********";

$user=$_SESSION['user'];

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query2 = "SELECT * FROM Pmess Where tname='$user'";

$result2 = mysql_query($query2) or die ("Error in query: $query2. ".mysql_error());
echo "<form method='POST'>";
$t=0;
while($row = mysql_fetch_row($result2)){
echo "<table cellpadding='0' cellspacing='0' width='373' border=1><tr><td><b>By:</b> $row[2]<br><br> <b>Subject:</b> $row[3]<br><br><b>Message:</b><br> $row[4]<br><br>Delete:<input type='checkbox' name='$row[0]' value='$row[0]'></td></tr></table><br>";
$t++;
}
echo "<input type='submit' name='sub' value='Delete'></form>";
if(isset($_POST['sub'])){
//Need something!//
?>
</html>[/code]

Share this post


Link to post
Share on other sites
Have your checkboxes load the values (id's) into an array.

Example:
[b]<input type='checkbox' name='delete[]' value='$row[0]'/>[/b]

$_POST['delete'] will now contain an array populated with the id's of messages to be deleted.

I take it you know what to do from here. [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

Share this post


Link to post
Share on other sites
thanks i new i have to use an array! i just could figure out how.....ok..i will try that!

Share this post


Link to post
Share on other sites
Glad to be of service.

Share this post


Link to post
Share on other sites

×

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.