我很困惑地使用我的表格中的第一行id
来传递我的模态形式。
显示我的模态的表格和按钮
<div id="ManageAccounts" class="tab-pane fade">
<h2>List of Customers</h2>
<table class="table table-hover">
<thead>
<tr>
<th>Costumer ID</th>
<th>Name</th>
<th>Address</th>
<th>Phone Number</th>
</tr>
</thead>
<tbody>
<?php
while ($row_costumer = mysqli_fetch_assoc($result_costumer)) {
$user_edit = $row_costumer['id'];
echo "<tr>";
echo "<td>" . $row_costumer['id'] . "</td>";
echo "<td>" . $row_costumer['name'] . "</td>";
echo "<td>" . $row_costumer['address'] . "</td>";
echo "<td>" . $row_costumer['phone_number'] . "</td>";
echo "<td>" . "<a class='edit-user btn btn-danger' href='#EditUser' data-toggle='modal' data-id='.$user_edit'>" . "<span class='glyphicon glyphicon-edit'>" . "</span>" . " Edit" . "</a>" . "</td>";
echo "<tr>";
}
?>
</tbody>
</table>
</div>
模态
<div class="modal fade" id="EditUser" tabindex="-1" role="dialog" aria-
labelledby="exampleModalLongTitle" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-
label="Close">
<span aria-hidden="true">×</span>
</button>
<h3 class="modal-title" id="exampleModalLongTitle">Update User</h3>
</div>
<div class="modal-body">
<form class="registerform" action="../includes/user_update.php"
method="POST">
<div class="form-group">
<input type="text" class="form-control" id="uname" name="uname"
required placeholder="Name">
</div>
<div class="form-group">
<input type="text" class="form-control" id="uaddress"
name="uaddress" required placeholder="Address" required>
</div>
<div class="form-group">
<input type="text" class="form-control" id="up_number"
name="up_number" required placeholder="Phone Number" required>
</div>
<div class="form-group">
<button type='submit' class="btn btn-primary lg btn-block"
name="submit">Save</button>
</div>
</form>
</div>
</div>
</div>
</div>
user_update.php
<?php
include '../includes/config.php';
if (isset($_POST['submit'])) {
$uname = $_POST['uname'];
$uaddress = $_POST['uaddress'];
$up_number = $_POST['up_number'];
$u_id = $_POST['id'];
}
$query = "UPDATE costumer_inf SET name = '$uname', address = '$uaddress',
phone_number = '$up_number' WHERE id = '$u_id'";
$result = mysqli_query($conn, $query);
header("location: ../admin/");
?>