删除按钮不删除数据库中的所有值

时间:2016-03-09 14:59:24

标签: php mysql

我在详细信息页面上创建了一个删除按钮,删除了必须删除的值....删除后似乎代码正常工作,因为它不会在详细信息页面上显示任何信息但是当我去的时候到PHPMyAdmin它仍然显示一些值...我使用三个表人,地址,简历后按删除人的值被删除但不是从地址和简历。

我的删除代码:

<?php
      $servername = "localhost";
      $username = "root";
      $password = "usbw";
      $dbname = "persons";

// Create connection
      $conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
      if ($conn->connect_error) {
         die("Connection failed: " . $conn->connect_error);
      }

      $id=$_GET['id']; 

      $stmt = $conn->prepare('DELETE FROM person WHERE person_id = ?'); 
      $stmt->bind_param('s', $id);                                         

      $result = $stmt->execute();    
      if ($result === FALSE) {
        die("Error: " . $stmt->error);
      }
      $conn->close();
?>

我在CASCADE上为address_id和cv_id设置了ON DELETE,它与person_cv和person_address有关系。此外,我不想为这个小问题开始一个新主题......当我按下删除时,它会转到一个名为http://localhost:8080/Website/delete.php?id=(randomid)的空白页面。我希望它返回到详细信息页面。

2 个答案:

答案 0 :(得分:0)

标题(&#34;位置:http://localhost:8080/Website/detailpage&#34;);

(或任何您的详细信息页面)

答案 1 :(得分:0)

检查foreignKey Cascade

<?php
    $servername = "localhost";
    $username = "root";
    $password = "usbw";
    $dbname = "persons";

    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
    }

    $id=$_GET['id']; 

    if ($conn->query(sprintf ( "DELETE FROM person WHERE person_id = '%s' ", mysql_real_escape_string ( $id ) ) )) {
        header('Location: detailpage.php'); 
    }
    else{
        printf("Errormessage: %s\n", $mysqli->error);
        exit();
    }

    $conn->close();
?>