- 您需要数据库连接才能做到这一点。
- 不要使用已弃用的 mysql_* 函数。检查mysqli和pdo。
- SQL注入阅读了它
这是为了学术,所以我会用 mysql_* 函数给你一个非常简单的答案
$id = intval($_GET['deleteId'], 0); //this function parses the param to int if it is not number there will be 0
if($id) //checking if id is true(not zero)
{
$query = mysql_query("DELETE FROM `kingswinfordcc_vehicles` WHERE `vehicleid` = '$id'");
header("Location: vehicle-table.php"); //after query moving to vehicle-table.php if query fail and show msg it this line won't move user to this page!
}
请记住,您需要 mysql 连接才能执行此类查询。
PDO解决方案:
<?php
/* Connect to an ODBC database using driver invocation */
$dsn = 'mysql:dbname=testdb;host=127.0.0.1'; //fill with proper data
$user = 'dbuser';
$password = 'dbpass';
$id = (int)$_GET['id'];
try{
$dbh = new PDO($dsn, $user, $password);
$st = $a->prepare("UPDATE `users` SET user=:id");
$st->bindParam(":id", $id, PDO::PARAM_INT);
$st->execute();
header("Location: vehicle-table.php");
//echo $st->rowCount(); //this line will show how many rows were deleted
}
catch (PDOException $e){
echo 'Error: ' . $e->getMessage();
}
?>