php使用id删除记录

时间:2016-02-14 12:16:01

标签: php html mysql

此程序用于在给出id时删除记录。

PHP:

if ($_GET['type']=="file"){

    $servername = "localhost";
    $username = "****";
    $password = "****";
    $dbname = "****";

    // Create connection
    $conn = mysqli_connect($servername, $username, $password, $dbname);
    // Check connection
    if (mysqli_connect_error($conn)) {
        die("Connection failed: " . mysqli_connect_error($conn));
    }
    $sql = "SELECT id,user, FROM CreationsAndFiles WHERE id =".$_GET['id']." LIMIT 1";
    $result = mysqli_query($conn,$sql);
    $row = mysqli_fetch_assoc($result);
    if ($row['user'] == $login_session){
        $sql = "DELETE FROM CreationsAndFiles WHERE id=".$_GET['id'];
        if(mysqli_query($conn, $sql)){echo "deleted";}
    }
    mysqli_close($conn);
    //header("location: index.php?page=CreationsAndFiles");
}

标题为type=file&id=9id=9的记录 它没有明显的理由不起作用。

1 个答案:

答案 0 :(得分:2)

您的SQL语法错误;

SELECT id,user, FROM CreationsAndFiles...
              ^ extra comma

应该只是

SELECT id,user FROM CreationsAndFiles...

您可能希望清理输入,例如,只需输入type=file&id=id很可能会做坏事。