无法删除数据但成功连接

时间:2016-04-28 03:59:00

标签: php

我已经尝试了删除查询的所有代码,它确实说'成功连接'但是当我放入数据时,它会出错。

这是我的html表单

<form action="testdel.php" method="post">
            IC:
            <input name="nama" type="text" />
            <input name="Submit" type="submit" value="delete"/>
            </form>

这是我的php:

<?php
                $con=mysqli_connect("localhost", "root", "","jpn") or die("Cannot connect to
                server.".mysqli_error($con));
                $nama=@$_POST["nama"];
                $sql_delete="DELETE FROM register WHERE nama='$nama' ";

                $sql_result=mysqli_query($con,$sql_delete);
                 if ($sql_result)
                     echo "Succesfully deleted";
                     else
                         echo "error due to selected data";

                ?>      

这是我的注册结构 register structure

1 个答案:

答案 0 :(得分:0)

您的解决方案

<?php
$con = mysqli_connect("localhost", "root", "", "jpn") OR die("MySQL connection error");
if (isset($_POST['nama'])) {
    $nama = $_POST['nama'];
    $deleteQuery = "DELETE FROM register WHERE nama = '" . $nama . "'";
    $delete = mysqli_query($con, $deleteQuery);

    if ($delete) {
        echo "Delete successful";
    } else {
        echo "Delete unsuccessful";
    }
}
?>

如果您仍然收到错误,也许您可​​以详细说明您收到的错误消息。