Hi… i want to delete multiple data from database, so how i can do that?? i search a lot of php coding from the internet, but it is not working…
this is my table…
<form id="form1" name="form1" method="post" action="">
<table width="427" border="1" align="center">
<tr bordercolor="#000000" bgcolor="#0000FF">
<td width="26" class="style6"> </td>
<td width="31" class="style6"><div align="center" class="style7">Bil</div></td>
<td width="147" class="style6"><div align="center" class="style7">Name</div></td>
<td width="96" class="style6"><div align="center" class="style12">Matrik Num </div></td>
<td width="93" class="style6"><div align="center" class="style12">Category</div></td>
</tr>
<?php
$room = $_POST['room'];
$sql = "SELECT * from info
WHERE room = '$room' ";
$result = mysql_query($sql) or die ("There's an error running on '$result'" .mysql_error());
$rows = mysql_fetch_array($result);
$totalRows= mysql_num_rows($result);
$i=$record; do
{
?>
<tr class="style16">
<td class="style16"><label>
<div align="center">
<input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $rows['matric']?>" />
</div>
</label></td>
<td class="style16"><div align="center"><span class="style16"><?php echo $i++?></span></div></td>
<td class="style16"><div align="center" class="style16">
<div align="left"><?php echo $rows['name']; ?> </div>
</div></td>
<td class="style16"><div align="center" class="style16"><?php echo $rows['matric']; ?> </div></td>
<td class="style16"><div align="center" class="style16"><?php echo $rows['unit']; ?> </div></td>
</tr>
<?php
}
while($rows = mysql_fetch_array($result));
?>
</table>
<div align="center">
<p align="center" class="style1">
<label>
<input name="Submit" type="submit" class="style16" id="Submit" value="Check Out" />
</label>
<label></label>
<span class="style1">
</span></p>
</form>
this is the code…
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST['Submit'])) && ($_POST['Submit'] == "Check Out"))
{
$matric = $_POST['matric'];
$deleteSQL = sprintf("DELETE FROM info WHERE matric= '". $_POST['checkbox'] ."'",
GetSQLValueString($_POST['matric'], "text"));
mysql_select_db($database_sistem_maklumat_pelajar, $sistem_maklumat_pelajar);
$Result1 = mysql_query($deleteSQL, $sistem_maklumat_pelajar) or die(mysql_error());
$deleteGoTo = "checkoutsuccess.php";
if (isset($_SERVER['QUERY_STRING']))
{
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $deleteGoTo));
}