problem on the delete multiple rows in mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
binboy
Forum Newbie
Posts: 1
Joined: Mon Nov 01, 2010 11:31 am

problem on the delete multiple rows in mysql

Post by binboy »

I want on the code following delete one or few rows (multiple rows) in the mysql, But unfortunately dont work,testing on the server and localhost but dont work.i want just use css and div, dont use tabel,i want act on the local and the server,please help me.

Code: Select all

<!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" />
<LINK rel=stylesheet type=text/css href="style.css">
<title>Untitled Document</title>
</head>

<body>
<?php
include('config.php');
$result = mysql_query("SELECT * FROM test_mysql ORDER BY name ASC");
$count=mysql_num_rows($result);
?>

<div class="container">
    <div class="header">   Header  </div>
    <div class="nav4" style="font-size:20px; font-weight:bold;">   1  </div>  
    <div class="nav4" style="font-size:20px; font-weight:bold;">   #  </div>  
    <div class="content" style="font-size:20px; font-weight:bold;">   Name  </div>
    <div class="nav3" style="font-size:20px; font-weight:bold;">   LastName  </div>
    <div class="sidebar" style="font-size:20px; font-weight:bold;">   Email  </div>
<?php
    $count=count($checkbox);  

while($row = mysql_fetch_array($result))
  {
  echo '<div class="chekbox"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="'.$rows[id].'"></idv>';
  echo '<div class="nav4">' . $row['id'] . '</div>';
  echo '<div class="content"><a href="update.php?id='.$row['id'].'">'.$row['name'].'</a></div>';
  echo '<div class="nav3">' . $row['lastname'] . '</div>';
  echo '<div class="sidebar">' . $row['email'] . '</div>';
  }
  if(isset($_POST['delete'])){
      $checkbox = $_POST['checkbox'];
   for($i=0;$i<$count;$i++){
      $del_id = $checkbox[$i];
      $sql = "DELETE FROM test_mysql WHERE id='$del_id'";
      $result = mysql_query($sql);
   }

   // if successful redirect to delete_multiple.php
   if($result){
      echo "<meta http-equiv=\"refresh\" content=\"0;URL=display.php\">";
   }
}
  
?> 
    <div class="delete"><form method="post" action="<?php $_SERVER['PHP_SELF'] ?>"><input name="delete" type="submit" id="delete" value=""></form></div>
<div class="footer">Footer</div>
</div>
</body>
</html>
tanx
Post Reply