While I am new to php i am trying to figure out what the error is while using delete operation i have a database table "local_admin" and the tuples are constituency, username and password with constituency set as primary key. The code is given below and also the data table is not populated in the page.Any help is greatly appreciated. Thanx.
<?php
session_start();
include("header.php");
$logout="You have successfully Loged out! Please log in to continue";
if(!isset($_SESSION['username']))
header("location:masteradmin.php");
else
$id=$_SESSION['username'];
if(isset($_POST['logout']))
{
session_destroy();
header("location:masteradmin.php");
}
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="voting"; // Database name
$tbl_name="local_admin"; // Table name
// Connect to server and select databse.
@mysql_connect("$host", "$username", "$password")or die("cannot
connect");
@mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<!--Content starts here-->
<div class="content">
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="<?php echo
$_SERVER['PHP_SELF']; ?>">
<table width="400" border="0" cellpadding="3" cellspacing="1"
bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="4" bgcolor="#FFFFFF"><strong>Delete Local Admin</strong>
</td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>Constituency</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Username</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Password</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['constituency']; ?>"></td>
<td bgcolor="#FFFFFF"><? echo $rows['constituency']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['username']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['password']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td>
</tr>
<?php
// Check if delete button active, start this
if(isset($_POST['delete']))
{
$checkbox = $_POST['checkbox'];
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM $tbl_name WHERE name='$del_id'";
$result = mysql_query($sql);
}
// if successful redirect to delete_multiple.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=deletelocaladmin.php\">";
}
}
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>
</div>
<?php include("footer.php"); ?>