我一直在創造一個工作人員目錄網頁aplication學習和測試我學到的東西,但有從我的MySQL數據庫所在的staff_id = staff_id從以前的delete一個頁面記錄問題IM從MySQL刪除記錄,它會重新記錄並填充字段,但是當我選擇「是」時不會刪除記錄。我不能使用PHP
任何幫助或指導做好將是巨大的:d因此按
<?php
# display all php errors
error_reporting(E_ALL);
ini_set('display_errors', 1);
# include dbConnection details
require '/includes/dbconn.php';
# if $staff_id is not empty, GET the id
if (!empty($_GET['staff_id'])) {
$staff_id = $_GET['staff_id'];
}
# check if data has been posted
if (!empty($_POST)) {
# modify the variable request from GET to POST
$staff_id = $_POST['staff_id'];
# delete data from joke table
$sql = "DELETE FROM staff WHERE staff_id = :staff_id";
$stmt = $DB_con->prepare($sql);
$stmt->bindValue(':staff_id', $staff_id);
$stmt->execute();
header("Location: Admin_View_Employee.php");
exit();
# display current record
} else {
$sql = "SELECT staff_id, forename, surname, job_role, joined, manager_id, extension, mobile, email, background_info, qualifications, achievements, username, password, level, dept_id
FROM staff
WHERE staff_id = :staff_id";
$stmt = $DB_con->prepare($sql);
$stmt->bindValue(':staff_id', $staff_id);
$stmt->execute();
$data = $stmt->fetch();
$staff_id = $data['staff_id'];
$forename = $data['forename'];
$surname = $data['surname'];
$job_role = $data['job_role'];
$manager_id = $data['manager_id'];
$joined = $data['joined'];
$extension = $data['extension'];
$mobile = $data['mobile'];
$email = $data['email'];
$background_info = $data['background_info'];
$qualifications = $data['qualifications'];
$achievements = $data['achievements'];
$dept_id = $data['dept_id'];
}
# if data is not found
if(!$data)
{
header("Location: Admin_View_Employee.php");
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Update Employee</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="css/style.css" type="text/css" />
</head>
<body>
<div>
<table width="100%" border="0">
<tbody>
<tr>
<td width="25%"><img src="images/beacon_logo.png" width="240" height="168" align="left"></td>
<td width="50%"><h1 style="text-align: center" border="0">Update Employee</h1></td>
<td width="25%"> </td>
</tr>
</tbody>
</table>
</div>
<?php include('Admin_Nav.php'); ?>
</tbody>
</table></p>
<div>
<form action="Admin_Delete_Employee.php?staff_id=<?php echo $staff_id ?>" method="post">
<input type="hidden" name="id" value="<?php echo $staff_id; ?>"/>
<p>Are you sure to delete this record?</p>
<table width="574">
<tr>
<th width="131">Staff ID</th>
<td width="84"><?php echo $staff_id;?></td>
</tr>
<tr>
<th>Forename</th>
<td><?php echo $forename;?></td>
</tr>
<tr>
<th>Surname</th>
<td><?php echo $surname;?></td>
</tr>
<tr>
<th>Job Role</th>
<td><?php echo $job_role;?></td>
</tr>
</tr>
</table>
<div>
<button type="submit">[Yes]</button>
<a href="Admin_View_Employee.php">[No]</a>
</div>
</form>
</div>
</body>
</html>
'NAME = 「ID」'!='$ _ POST [ 'staff_id']'...或者把它作爲'$ _GET'因爲你也正在發送這種方式'?staff_id = <?PHP的echo $ staff_id?''你只需要取消其他覆蓋。 – chris85
你得到了什麼錯誤信息,你有什麼問題的確切代碼段? –