2017-01-11 93 views
-3

我tryed一切辦法,但它不工作PHP PDO刪除按鈕

option.php

if (isset($_GET['agentsdelete'])) { 

$agents_id=$_GET['agents_id']; 
$delete=$db->prepare("DELETE FROM agents WHERE agents_id=:agents_id"); 
$control=$delete->execute(array(
    'agents_id' => $_GET['agents_id'] 
)); 

if ($control) { 

    Header("Location:agents.php??durum=ok&agents_id=$agents_id"); 

} else { 

    Header("Location:agents.php??durum=no&agents_id=$agents_id"); 
} 

這是PHP腳本

的index.php

<a href="option.php?agentsdelete=<?php echo $agentget['agents_id']; ?>" class="btn btn-danger btn-sm btn-icon icon-left"> 
      <i class="entypo-cancel"></i> 
      Delete 
     </a> 

而這一次的index.php其中

+0

按鈕目前尚不清楚你要問在這裏,請回顧一下(HTTP [我如何問一個很好的問題?]://計算器.COM /幫助/如何對問)然後回來和編輯您的帖子這樣的措辭的方式,人們實際上可以幫助你。 – DaveyDaveDave

+0

'$控制= $刪除 - >執行(陣列( 'agents_id'=> $ _GET [ 'agents_id']'應'$控制= $刪除 - >執行(陣列( ':agents_id'=> $ _GET ['agents_id']'粗心的錯誤 –

回答

0
<?php 

if (isset($_GET['agentsdelete'])) { 

    $agents_id = $_GET['agentsdelete']; 



    $delete = $db->prepare("DELETE FROM agents WHERE agents_id= ? "); 

    if ($delete->execute(array(
     $agents_id 
    ))) { 

     Header("Location:agents.php??durum=ok&agents_id=$agents_id"); 

    } else { 

     Header("Location:agents.php??durum=no&agents_id=$agents_id"); 
    } 
} 

?>