PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 300,416 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,564 people online right now. Registration is fast and FREE... Join Now!




problem on deleting using multiple checkboxes

 

problem on deleting using multiple checkboxes

peihwa330

30 Jun, 2009 - 06:11 PM
Post #1

D.I.C Head
**

Joined: 15 Mar, 2007
Posts: 62



Thanked: 1 times
My Contributions
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">&nbsp;</td>
  </tr>
  <tr>
    <td width="192" height="648">&nbsp;</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">&nbsp;</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]&nbsp; &nbsp;"; 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>';}
                       
}

?>


User is offlineProfile CardPM
+Quote Post


noorahmad

RE: Problem On Deleting Using Multiple Checkboxes

30 Jun, 2009 - 10:05 PM
Post #2

Webmaster
Group Icon

Joined: 12 Mar, 2009
Posts: 2,018



Thanked: 125 times
Dream Kudos: 1350
My Contributions
This Tutorial will help you
http://www.dreamincode.net/forums/showtopic108410.htm
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 11:31PM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month