所有我想做的就是有一个简单的文本形式从sql数据库中删除记录 它返回记录被删除但它实际上从未删除记录。
variablesremove.php:
html表单图片:
remove.php:
remove.php:
require('variablesremove.php');
$user = "#";
$password = "#";
$host = "localhost";
$database= "#";
$connection= mysqli_connect ($host, $user, $password);
if (!$connection) {
die ('Could not connect:' . mysql_error());
}
mysqli_select_db($database, $connection);
$deleterow = "DELETE FROM licenses WHERE serialNumber='$serialNumber'";
if($deleterow !== FALSE) {
echo("The row has been deleted.");
} else {
echo("The row has not been deleted.");
}
答案 0 :(得分:3)
您需要使用mysqli_query()
执行删除命令。
$deleteRow = "DELETE FROM licenses WHERE serialNumber='$id'";
if (mysqli_query($connection, $deleteRow)) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . mysqli_error($conn);
}
mysqli_close($conn);
答案 1 :(得分:2)
...
mysqli_select_db($database, $connection);
$deleterow = "DELETE FROM licenses WHERE serialNumber = '$serialNumber'";
if(mysqli_query($conn, $deleterow)) {
echo("The row has been deleted.");
} else {
echo("The row has not been deleted.");
}
...
答案 2 :(得分:1)
您可以将此作为示例 -
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// sql to delete a record
$sql = "DELETE FROM MyGuests WHERE id=3";
if (mysqli_query($conn, $sql)) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . mysqli_error($conn);
}
mysqli_close($conn);
?>
答案 3 :(得分:1)
您实际应该使用参数化查询来运行此语句。
在它的现有形式中,它受到SQL注入攻击。
if($deleterow = $mysqli->prepare("DELETE FROM licenses WHERE serialNumber = ?") {
$deleterow->bind_param("s", $id);
if ($deleterow->execute()) {
printf("The row has been deleted.\n");
}else{
echo "Error deleting record: " . mysqli_error($conn);
}
} else {
printf("Error preparing the query: %s\n",$deleterow);
}
$mysqli->close();
答案 4 :(得分:1)
感谢所有人的帮助!
这是工作解决方案!
<?php
require('variablesremove.php');
$user = "#";
$password = "#";
$host = "#";
$database = "#";
$connection= mysqli_connect ($host, $user, $password);
if (!$connection)
{
die ('Could not connect:' . mysql_error());
}
mysqli_select_db($connection, "$database") or die ("Couldn't select the database.");
$deleteRow = "DELETE FROM licenses WHERE serialNumber='$id'";
if (mysqli_query($connection, $deleteRow)) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . mysqli_error($connection);
}
mysqli_close($connection);
?>