如何使用php删除数据库中的记录?我有一些代码在删除但它不会删除记录

时间:2017-10-08 13:23:42

标签: javascript php html

这是我的deleteriddle.php,但它不起作用。请帮帮我

<?php

require("dbcon.php");

$ridid = isset ($_GET['riddleid'])?$_GET['riddleid']:"";
$query = sprintf("DELETE FROM riddle WHERE riddleid= '$ridid'");
$result = mysql_query($query);

if (!$result) {
    die('Invalid query: ' . mysql_error());
}
else {
    echo '<script type="text/javascript">
    alert("Riddle successfully delete");
    window.location.href = "viewriddle.php";
    </script>';
}

mysql_close($dbcon);

?>

1 个答案:

答案 0 :(得分:0)

试试这个:

$query = sprintf("DELETE FROM riddle WHERE riddleid= %u", $ridid);