I have a form with multiple checkboxes. When submited a checked box will update a sql-row, all checked gets the same value. Now I'm trying to add an other <input type="checkbox" /> in the same form, that if checked will erase a row in the sql-table.
/////////////////////////////////////
//
// Start checkbox
// If checkbox active start:
//
/////////////////////////////////////
if(isset($_POST['check'])){
foreach ($_POST['checkbox'] as $c){
$result = mysql_query("UPDATE resultat SET kontroll = 'ok!' WHERE id = '$c'") or die (mysql_error());
}
}
$sql="SELECT * FROM resultat WHERE kontroll = 'unchecked' ORDER BY user ASC";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
echo "\n\t\t\t<form action=\"$PHP_SELF\" method=\"POST\">";
echo "\n\t\t\t<table>";
echo "\n\t\t\t<tr>";
echo "\n\t\t\t<td></td>";
echo "\n\t\t\t<td><strong>Ok</strong></td>";
echo "\n\t\t\t<td><strong>SäljID</strong></td>";
echo "\n\t\t\t<td><strong>Telefonnummer</strong></td>";
echo "\n\t\t\t<td><strong>Företaget</strong></td>";
echo "\n\t\t\t<td><strong>Produkt</strong></td>";
echo "\n\t\t\t</tr>";
$i = 1;
while($rows=mysql_fetch_array($result)){
echo "\n\t\t\t<tr>";
echo "\n\t\t\t<td>$i.</td>";
echo "\n\t\t\t<td><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"".$rows['id']."\" /></td>";
echo "\n\t\t\t<td>".$rows['user']."</td>";
echo "\n\t\t\t<td>".$rows['telenr']."</td>";
echo "\n\t\t\t<td>".$rows['klient']."</td>";
echo "\n\t\t\t<td>".$rows['produkt']."</td>";
echo "\n\t\t\t</tr>";
$i++;
}
echo "\n\t\t\t<tr>";
echo "\n\t\t\t<td colspan=\"5\"><input name=\"check\" type=\"submit\" id=\"check\" value=\"Ok\" class=\"input submit\"></td>";
echo "\n\t\t\t</tr>";
echo "\n\t\t\t </table>";
echo "\n\t\t\t</form>";
/////////////////////////////////////
//
// End checkbox
//
/////////////////////////////////////
I thought that I would be able to add a <input> with erase. See to it that erase-checkbox starts a "new" if() that will erase a row. I haven't manage to do it... :-(