hi there,
I had this problem since very long and till now I still could not figure out how to solve it. The problem I had is the delete button is not working. No rows are deleted or either it echo out the "deletion could not be processed." which is the result of clicking the delete button. Anyone could help me out with this?
admin.php
CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table width="999" height="824" border="1" align="center">
<tr>
<td height="129" colspan="2"> </td>
</tr>
<tr>
<td width="192" height="648"> </td>
<td align="center" valign="top"> <form name="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<select name="list" >
<option selected="selected" value="Blog posts">Blog posts</option>
<option value="News">News</option>
<option value="Announcement">Announcement</option>
</select>
<input type="submit" name="display" value="Display" />
<?php include("display_allposts.php"); ?>
</form></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table>
</body>
</html>
delete.php
CODE
<head>
<style type="text/css">
div
{
width:807px;
height:650px;
overflow: scroll
}
</style>
</head>
<div>
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="spps"; // Database name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
if(isset($_POST['display']))
{
$tables = array("Blog posts"=>"blog","News"=>"news", "Announcement"=>"announcement");
$orderby = array("Blog posts"=>"blog_id","News"=>"news_id", "Announcement"=>"announ_id");
$category = $_POST['list'];
$sql = "SELECT * FROM ".$tables[$category]." ORDER BY ".$orderby[$category]." ASC";
$result=mysql_query($sql);
$newid = $orderby[$category];
echo "$newid";
while($nt=mysql_fetch_array($result)){
$id = $nt[$orderby[$category]];
print ("<table width='780' border='1'>
<tr>
<td width='677'>"); echo "$nt[title] "; print("</td>
<td width='100'>"); echo "$id<br>"; print("</td>
<td width='100'>"); echo "$category<br>"; print("</td>
<td width='30'>"); ?> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo "$id"; ?>"></td><?php print("</td>
</tr>
</table>");
}
}
?><form name="input" action="display_allposts.php" method="post">
<input type="submit" name="delete" value="Delete"></form>
<?php
if(isset($_POST['delete']))
{
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM ".$tables[$category]." WHERE $newid = $del_id";
$result = mysql_query($sql);
}
if($result){
$alert = "Deletion is successful.";
echo '<script type="text/javascript">alert("'.$alert.'");</script>';
}
else{
$alert = "Deletion could not be processed. Please try again.";
echo '<script type="text/javascript">alert("'.$alert.'");</script>';}
}
?>