简体   繁体   English

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

[英]Delete button not deleting all values from database

I created a delete button on my detail page which deletes the values which must be deleted how ever.... After deleting it's seems like the code is working because it doens't show any information on the detailpage but when I go to PHPMyAdmin it's still showing some values... I am using three tables person, address, cv after pressing delete the values from person is deleted but not from address and cv. 我在详细信息页面上创建了一个删除按钮,该按钮删除了必须删除的值。...删除后,代码似乎在起作用,因为它在详细信息页面上不显示任何信息,但是当我转到PHPMyAdmin时,仍然显示一些值...按“删除”后,我正在使用三个表“人”,“地址”,“简历”,但不从“人”和“简历”中删除值。

My delete code: 我的删除代码:

<?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();
?>

I have ON DELETE set up on CASCADE for both address_id and cv_id which has a relation with person_cv and person_address. 我在CASCADE上为address_id和cv_id设置了ON DELETE,这与person_cv和person_address有关系。 Also I do not want to start a new topic for this small question... When I press delete it is going to a empty page called http://localhost:8080/Website/delete.php?id=(randomid) I want it to go back to the detailpage. 我也不想为这个小问题开始新的话题...当我按Delete键时,它将转到一个空页面,名为http:// localhost:8080 / Website / delete.php?id =(randomid)我想要返回详细页面。

header("Location: http://localhost:8080/Website/detailpage "); header(“ Location: http:// localhost:8080 / Website / detailpage ”);

(or whatever your detail page is called) (或您的详细信息页面所称的任何内容)

check foreignKey Cascade 检查foreignKey级联

<?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();
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM