此程序用于在给出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=9
有id=9
的记录
它没有明显的理由不起作用。
答案 0 :(得分:2)
您的SQL语法错误;
SELECT id,user, FROM CreationsAndFiles...
^ extra comma
应该只是
SELECT id,user FROM CreationsAndFiles...
您可能希望清理输入,例如,只需输入type=file&id=id
很可能会做坏事。