2017-04-01 68 views
0
<?php include("header.php"); ?> 
    <?php 
    if (@$_POST['delete']=="Delete"){ 
     $count=count($_POST['delbx']); 
     for($i=0;$i<$count;$i++){ 
      $delete = "DELETE FROM admin WHERE a_id='".$_POST['delbx'][$i]."'"; 
      $resulty = mysqli_query($conn, $delete) or die(mysql_error()); 
      $select_delete = "SELECT `a_image` FROM admin WHERE a_id='".$_POST['delbx'][$i]."'"; 
      $resultrowdy = $conn->query($select_delete); 
      $rowdy = $resultrowdy->fetch_assoc(); 
      $path="admin/".$rowdy['a_image']; 
      echo $path; 
      unlink($path); 
      echo '<script>window.location="view_user.php"</script>'; 
     } 
    } ?> 

    <div class="table-responsive"> 
     <table class="table"> 
      <caption>All Users</caption> 
      <?php 
      $sql = "SELECT a_id, a_name, a_phone, a_password, a_role, a_mail, a_image FROM admin"; 
      $result = $conn->query($sql); 

      if ($result->num_rows > 0) {?> 
       <thead> 
        <tr> 
         <th><form action="view_user.php" method="post"><input name="delete" type="submit" id="delete" value="Delete"></th><th>S. No.</th> <th>Name</th> <th>Phone No.</th> <th>Mail Id</th> <th>Role</th> <th>Password</th> <th>Image</th> 
        </tr> 
       </thead> 
       <?php 
       while($row = $result->fetch_assoc()) { ?> 
        <tbody> 
         <tr> 
          <th scope="row"> 
           <?php echo $row["a_id"]; ?> 
          </th> 
          <td align="center" bgcolor="#FFFFFF"> 
           <input name="delbx[]" type="checkbox" id="delbx[]" value="<?php echo $row["a_id"]; ?>" /> 
          </td> 
          <td> 
           <?php echo $row["a_name"]; ?> 
          </td> 
          <td> 
           <?php echo $row["a_phone"]; ?> 
          </td> 
          <td> 
           <?php echo $row["a_mail"]; ?> 
          </td> 
          <td> 
           <?php echo $row["a_role"]; ?> 
          </td> 
          <td> 
           <?php echo $row["a_password"]; ?> 
          </td> 
          <td> 
           <img src="admin/<?php echo $row["a_image"]; ?>" width="60" height="40"> 
          </td> 
          <th> 
           <a href="admin_update.php?editid=<?php echo $row["a_id"];?>" style="color:#FFF;">Edit</a> 
          </th> 
         </tr> 
        </tbody> 
      <?php 
       } 
      } else { 
       echo "0 results"; 
      }?> 
      </table> 
     </form> 
    </div> 
    <?php include("footer.php"); ?> 

我提到的代碼並不是從源文件夾中刪除多個圖像,而是刪除多個數據從數據庫,而我試圖刪除圖像從源文件夾連同數據請幫助提前致謝我想通過PHP從源文件夾中刪除多個圖像,但從文件夾刪除多個圖像的代碼不起作用

+0

你必須在你的數據庫中排列確切的文件名,然後才能繼續刪除。 – Anonymous

+0

unlink($ conn,$ path);我試過但不工作 –

回答

0

其中一個問題是您正在刪除該行並嘗試從刪除的行中選擇圖像列.. 不使用用戶提供的變量直接在您的查詢中

喲你的代碼應該是

for($i=0;$i<$count;$i++){ 
     $select_delete = "SELECT `a_image` FROM admin WHERE a_id='".$_POST['delbx'][$i]."'"; 
     $resultrowdy = $conn->query($select_delete); 
     $rowdy = $resultrowdy->fetch_assoc(); 

     $delete = "DELETE FROM admin WHERE a_id='".$_POST['delbx'][$i]."'"; 
     if(mysqli_query($conn, $delete)){ 
     $path="admin/".$rowdy['a_image']; 
     unlink($path); 
     echo '<script>window.location="view_user.php"</script>'; 
     } 
    } 
+0

得到它的先生,我必須先選擇圖像coloumn刪除查詢之前,然後刪除數據? –

+0

@v Sugumar先生謝謝你教我1課重要一課:) –

相關問題