im pretty new to php, though not new enough for this to go into newbie forum i guess. basically what i have is a SQL query which produces an array of results in a table. I have it generate a checkbox on each row. I want to be able to hit the submit button and an SQL query Delete the rows according to which check boxes were selected. i have this to generate my table and check boxes:
<form name="form2" method="post" action="act.php">
<table width="544" border="0">
<tr>
<td width="538"><span class="style40">
<span class="style35">
<input type="submit" name="Submit" value="Delete">
</span></span></td>
</tr>
<tr>
<td><span class="style40">
<?
session_start();
include 'db.php';
$search = $user;
$query = "select * from mail WHERE touser='$search'";
$result = mysql_db_query("ss", $query);
$sql_username_check = mysql_query("SELECT touser FROM mail WHERE touser='$username'");
$mails = mysql_num_rows($sql_username_check);
if ($mails>0)
{
echo "<table width=100% id='result' align=left <table border=1 cellpadding=1 cellspacing=0 class=borderTable bordercolor=#FFFFFF><tr>
<td align=left bgcolor=#EDEDED><p class=style35><input id='allbox' name='allbox' onclick='checkAll(this);' type='checkbox' />
</td>
<td align=left bgcolor=#EDEDED><p class=style35>From</td>
<td align=left bgcolor=#EDEDED><p class=style35>Subject</td>
<td align=left bgcolor=#EDEDED><p class=style35>Date</td>
</tr></font>";
while ($r = mysql_fetch_array($result)) { // Begin while
$fromuser = $r["fromuser"];
$idnumber = mysql_query("SELECT * FROM users WHERE username='$fromuser'");// for profile display
$userid = mysql_result($idnumber,0,"userid");
$sub = $r["sub"];
$date = $r["date"];
$id = $r["id"];
$message = $r["message"];
$read = $r["beenread"];
if ($read==1) { $colour = "#FFFFFF";} else { $colour = "#EDEDED"; }
$Text = "<p class=style35><a href=profile.php?id=$userid; style=color:#0099FF>$fromuser</a>";
$Text2 = "<p class=style35><a href=mail_readmsg.php?msg=$r[id] style=color:#0099FF>$sub</a>";
echo "<p class=style35><tr>
<td align=left bgcolor=$colour><input type='checkbox' name='box$id' value='$id'></td> //not sure HERE!!!!!! each check box must be unique right!?//
<td align=left bgcolor=$colour>$Text</td>
<td align=left bgcolor=$colour>$Text2</td>
<td align=left bgcolor=$colour><p class=style35>$date</td>";
} // end while
echo "</table>";
} else { echo "<p class=style35><strong>-You have no new messages.-"; }
?>
</span></td>
</tr>
</table>
</form>
the form i gave there has the action of act.php:
//dbconnect//
$selected = $_POST['form2'];
for($i = 0; $i < $MAXID; $i++) ///maxid ???
if($_POST['box$i']=='on') {
mysql_query("DELETE FROM mail WHERE id='$i'") or die (mysql_error());
} else {}
include 'mail_read.php'; ?>
if you follow it you should understand my train of thought? i wasnt sure about the naming of each or how to determin a maxid for my loop?
Thanx alot guys, iv got myself in a right mess and i got a lot less sleep last night with my mind ticking over this problem. Thanx again.