0

hello... i need help from you all.. i am still new in php.. i hope you all can help me.. i am desperate. i can't delete delete data(delete multiple row from mysql using check box).
this is my coding.. the cooperation is greatly appreciated. i have 2 file
this is my coding

1 file = test1.php
<html>
<HEAD>
<?php session_start(); ?>
<?php

include("db_connect.php"); //connection
mysql_select_db($database_localhost, $conn)or trigger_error(mysql_error(),E_USER_ERROR);

$result=mysql_query("SELECT * FROM cek1a");
?>
<script language=javascript>
function validate()
{
var r=confirm("Adakah anda pasti ingin padam?")

  if (r==true)
    return true;
  else
    return false;
}

</script>
</head>

<table bordercolor="#CCCCCC" border='1' cellspacing='1' cellpadding='1'>

<tr>
<form name="test1" method="post" action="test2.php" onSubmit="return validate()">
<tr>
<th bgcolor="#6495ED">NoCek</TH>
<th bgcolor="#6495ED">NAMA </TH>
<th bgcolor="#6495ED">JUMLAH</TH>
<th bgcolor="#6495ED">TUJUAN</TH>
</TR>
<?php
while($row=mysql_fetch_array($result))
{
?>
<tr>
<td align="center"><?php echo $row['noC'];?></td>
<td align="center"><?php echo $row['name'];?></td>
<td align="center"><?php echo $row['jumlah'];?></td>
<td align="center"><?php echo $row['tujuan'];?></td>
<td align="center"><input type="checkbox" name="delete[]" value="<?php echo $row['noC'];?>"></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4">
<CENTER><input type="submit" value="HAPUS"></CENTER>

</td>
</tr>
</form>


</table>
</body>
</html>

second file = test2.php


<?php
include("db_connect.php");


if (isset($_POST['delete']) && is_array($_POST['delete']))
{
foreach ($_POST['delete'] as $num => $value)
{
$sql="delete  from cekla where noC='$value'";
$result=mysql_query($sql);
}
}
header("location:test1.php");
?>

i hope you all can help me. :)

Edited by pyTony: fixed formatting

2
Contributors
1
Reply
4
Views
5 Years
Discussion Span
Last Post by vibhaJ
0

1) Check spelling of table name. once you have "cek1a" and second is "cekla".
2) if spell is proper and still its not working then add below code on top of test2.php and post output.

echo '<pre>';
print_r($_POST['delete']);
exit;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.