我正在用php创建一个表,用户可以登录并编辑那里的记录。 我已经显示了所有信息,但无法编辑记录。
<table id="example" class="display responsive-table ">
<thead>
<tr>
<th>#</th>
<th width="95">Employee Type</th>
<th width="95">Firstname</th>
<th width="95">Lastname</th>
<th width="95">Email</th>
<th width="95">Phone</th>
<th width="95">Address</th>
<th width="95">City</th>
<th width="95">Country</th>
<th width="95">Dob</th>
<th width="95">Description</th>
<th width="95">Update</th>
<th width="95">Delete Employee</th>
</tr>
</thead>
<tbody>
<?php
$eid=$_SESSION['eid'];
$sql = "SELECT LeaveType, ToDate, FromDate, email, phone, address, city, country, dob, Description, Status
FROM tblleaves
WHERE empid=:eid";
$query = $dbh -> prepare($sql);
$query->bindParam(':eid',$eid,PDO::PARAM_STR);
$query->execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
$cnt=1;
if($query->rowCount() > 0) {
foreach($results as $result) { ?>
<tr>
<td> <?php echo htmlentities($cnt);?></td>
<td><?php echo htmlentities($result->LeaveType);?></td>
<td><input id="todate" name="todate" type="text" value="<?php echo htmlentities($result->ToDate);?>" autocomplete="off" required></td>
<td><input id="formdate" name="fromdate" type="text" value="<?php echo htmlentities($result->FromDate);?>" autocomplete="off" required></td>
<td><input id="email" name="email" type="text" value="<?php echo htmlentities($result->email);?>" autocomplete="off" required></td>
<td><input id="phone" name="phone" type="tel" value="<?php echo htmlentities($result->phone);?>" autocomplete="off" required></td>
<td><input id="address" name="address" type="text" value="<?php echo htmlentities($result->address);?>" autocomplete="off" required></td>
<td><input id="city" name="city" type="text" value="<?php echo htmlentities($result->city);?>" autocomplete="off" required></td>
<td><input id="country" name="country" type="text" value="<?php echo htmlentities($result->country);?>" autocomplete="off" required></td>
<td><input id="dob" name="dob" type="text" value="<?php echo htmlentities($result->dob);?>" autocomplete="off" required></td>
<td><input id="description" name="description" type="text" value="<?php echo htmlentities($result->Description);?>" autocomplete="off" required></td>
<td><button type="submit" name="update" id="update" class="waves-effect waves-light btn indigo m-b-xs">UPDATE</button></td>
<td><a href="leavehistory.php?del=<?php echo htmlentities($result->id);?>" onclick="return confirm('Do you want to delete');"> <i class="material-icons">delete_forever</i></a></td>
</tr>
<?php
$cnt++;
}
}
?>
</tbody>
</table>
该表应向您显示用户记录,并允许用户更改它们。
感谢它现在正在运行并成功发布,但是没有更新数据库
这是我的更新代码:
$eid=intval($_GET['empid']);
if(isset($_POST['update']))
{
$todate=$_POST['todate'];
$fromdate=$_POST['fromdate'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$address=$_POST['address'];
$city=$_POST['city'];
$country=$_POST['country'];
$dob=$_POST['dob'];
$description=$_POST['description'];
$sql="update tblleaves set ToDate=:todate,FromDate=:fromdate,email=:email,phone=:phone,address=:address,city=:city,country=:country,dob=:dob,Description=:description where empid=:eid";
$query = $dbh->prepare($sql);
$query->bindParam(':todate',$todate,PDO::PARAM_STR);
$query->bindParam(':fromdate',$formdate,PDO::PARAM_STR);
$query->bindParam(':email',$email,PDO::PARAM_STR);
$query->bindParam(':phone',$phone,PDO::PARAM_STR);
$query->bindParam(':address',$address,PDO::PARAM_STR);
$query->bindParam(':city',$city,PDO::PARAM_STR);
$query->bindParam(':country',$country,PDO::PARAM_STR);
$query->bindParam(':dob',$dob,PDO::PARAM_STR);
$query->bindParam(':description',$description,PDO::PARAM_STR);
$query->bindParam(':eid',$eid,PDO::PARAM_STR);
$query->execute();
$msg="Employee record updated Successfully";
}