dpi96151 2016-03-23 09:46
浏览 42

PHP删除功能失败,没有错误

In the top of my admin PHP (admin.php), I have loaded data from "Sport" table in "DogSport" MySQL database. After clicking "Edit" link of a particular record, I can edit, delete that record on "editform2.php". Even on that page, I can also insert a new record.

Problem: Deleting first and second records do not work! Deleting all following records work fine. This problem only with deleting functionality.

admin.php

I have uploaded necessary files, you can also use to check it including database .sql script. Your help is appreciated.

https://www.dropbox.com/s/wn40u93oa1sxcph/SO.rar?dl=0

Code segment - admin.php

include("dbconnect.inc.php");
//Retrieving Data
$query1 = "SELECT * FROM Sport ORDER BY SportId ASC";
$result2 = mysqli_query($con, $query1);
$rows = mysqli_num_rows($result2);
$i = 0;
if ($rows == 0)
    echo "<br/>There are no records";
else {
    echo "<table id='sport'>";
    echo "<tr><th>Sport Id</th><th>Sport Name</th><th>Description</th></tr>";

    while ($row = mysqli_fetch_array($result2)) {
        echo "<tr><td>" . $row["SportId"] . "</td><td>" . $row["SportName"] . "</td><td>" . $row["Description"] .
        "</td><td> <a href='editform2.php?id=" . $row["SportId"] . "' target='_blank'>Edit</a></td></tr>";

        $i++;
    }
    echo "</table>";
}

Code segment - editform2.php

if (isset($_POST["delete"])) {
    $id = $_GET["id"];
    include("dbconnect.inc.php");
    $query3 = "DELETE FROM Sport WHERE SportId=$id";
    mysqli_query($con, $query3);
    echo "<h1>Deleted Successfully</h1>";
    mysqli_close($con);
}

UPDATE!!!! I get this error now

DogSport is in use.Error: DELETE FROM Sport WHERE SportId=2 Cannot delete or update a parent row: a foreign key constraint fails (dogsport.orders, CONSTRAINT orders_ibfk_1 FOREIGN KEY (EqId) REFERENCES equipment (EqId))

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
    • ¥30 ppOCRLabel导出识别结果失败
    • ¥15 Centos7 / PETGEM
    • ¥15 csmar数据进行spss描述性统计分析
    • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
    • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
    • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
    • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
    • ¥15 运动想象脑电信号数据集.vhdr
    • ¥15 三因素重复测量数据R语句编写,不存在交互作用