嗨,我已經創建了一個刪除頁面,當我剛剛提交表單並且URL爲http://localhost/delete-session.php時無法工作,但是一旦我將URL更改爲http://localhost/delete-session.php?id=1它可行,我缺少什麼在我的代碼中讓它起作用?刪除頁面PHP MYSQL
<h1>Delete Page</h1>
<h3>Enter the booking number of the session you would like to delete!</h3>
<form action ="delete-session.php" method="post">
Booking ID:(Refer To Database):<input type="text" name="booking">
這是PHP
if(isset($_GET['booking'])){
$id=$_GET['booking'];
if(!is_numeric($id)){
echo "sorry, there appears to have been an error.";
exit;
}
} else {
echo "sorry, there appears to have been an error.";
exit;
}
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "olympics";
$conn = mysqli_connect($servername, $username, $password, $dbname);
$id=$_GET['id'];
if(!is_numeric($id)){
echo "Sorry, there is an error";
exit;
}
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql="DELETE from olympiics where booking='$id'";
echo $sql;
if (mysqli_query($conn, $sql)) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . mysqli_error($conn);
}
mysqli_close($conn);
太感謝你了哥們你是一個真正的生命的救星!我如何選擇這個作爲幫助他人的答案? – cpprr
以下是官方說明http://stackoverflow.com/help/someone-answers – RiggsFolly