我有一个包含客户详细信息的数据库,我想在表格中查看所有这些详细信息。我希望每个名称旁边都有一个编辑按钮,例如,管理员需要更新用户名。当管理员点击编辑时,例如在“jessica”行上,他们将被带到另一个页面,该页面将显示所有jessicas详细信息,管理员可以更新这些并将它们保存到数据库。到目前为止,在我的第一页上我有这个:它发布到我正在努力的下一页:
<?php
// the preparation
include ("dbConnect.php");
$query = $db->prepare("select * from customer");
$query->execute();
// Display search result
if (!$query->rowCount() == 0) {
echo "<table id=\"example\" style=\"font-family:arial;color:#ffffff;\" class=\"table table-striped table-bordered\" style=\"width:100%\">";
echo "<thead><tr>
<th style=\"border-style:solid;border-width:3px;border-color:#575757;background:#575757;\">ID</th>
<th style=\"border-style:solid;border-width:3px;border-color:#575757;background:#575757;\">Forename</th>
<th style=\"border-style:solid;border-width:3px;border-color:#575757;background:#575757;\">Surname</th>
<th style=\"border-style:solid;border-width:3px;border-color:#575757;background:#575757;\">Telephone</th>
<th style=\"border-style:solid;border-width:3px;border-color:#575757;background:#575757;\">Address</th>
<th style=\"border-style:solid;border-width:3px;border-color:#575757;background:#575757;\">Medical Conditions</th>
<th style=\"border-style:solid;border-width:3px;border-color:#575757;background:#575757;\">DOB</th>
<th style=\"border-style:solid;border-width:3px;border-color:#575757;background:#575757;\">Email</th>
<th style=\"border-style:solid;border-width:3px;border-color:#575757;background:#575757;\">Password</th>
<th style=\"border-style:solid;border-width:3px;border-color:#575757;background:#575757;\">Last Login</th>
<th style=\"border-style:solid;border-width:3px;border-color:#575757;background:#575757;\">Edit</th>
</tr></thead><tbody>";
$position = 1;
while ($results = $query->fetch()) {
$count = count($results);
echo "<tr><td style=\"border-style:solid;border-width:1px;border-color:#D3D3D3;\">";
echo $results['id'];
echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#D3D3D3;\">";
echo $results['forename'];
echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#D3D3D3;\">";
echo $results['surname'];
echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#D3D3D3;\">";
echo $results['telephone'];
echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#D3D3D3;\">";
echo $results['address'];
echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#D3D3D3;\">";
echo $results['medical_conditions'];
echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#D3D3D3;\">";
echo $results['dob'];
echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#D3D3D3;\">";
echo $results['email'];
echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#D3D3D3;\">";
echo $results['password'];
echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#D3D3D3;\">";
echo $results['last_login'];
echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#D3D3D3;\">";
echo '<input type="submit" class="btn btn-primary" value="Edit" href="editDetails.php">';
//echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#D3D3D3;\">";
}
}
if(isset($_POST['submit'])){
$id = $_POST['id'];
$forename = $_POST['forename'];
$surname = $_POST['surname'];
$telephone = $_POST['telephone'];
$address = $_POST['address'];
$medical_conditions = $_POST['medical_conditions'];
$dob = $_POST['dob'];
$email = $_POST['email'];
$password = $_POST['password'];
$last_login = $_POST['last_login'];
if($id !=''||$forename !=''||$surname !=''||$telephone !=''||$address !=''||$medical_conditions !=''||$dob !=''||$email !=''||$password !=''||$last_login !=''){}
$query = $db->prepare("INSERT INTO customer values (id, :forename, :surname, :telephone, :address, :medical_conditions, :dob, :email, :password, :last_login)");
$dbParams = array('id'=>$id, 'forename'=>$forename, 'surname'=>$surname, 'telephone'=>$telephone, 'address'=>$address, 'medical_conditions'=>$medical_conditions, 'dob'=>$dob, 'password'=>$password, 'last_login'=>$last_login);
$query->execute($dbParams);
}
?>