我是PHP新手,仍在學習語言。我創建了一個php頁面,可以顯示我的數據庫中的所有記錄(稱爲view_users.php)。我還創建了兩個按鈕「編輯」和「刪除」。如何通過單擊「編輯」按鈕來編輯php表中的記錄?
我希望能夠編輯特定行上的記錄,當我點擊附在其上的「編輯」按鈕時。有沒有一種方法可以在同一頁面上做到這一點(view_users.php)。
下面是view_users.php
<html>
<head lang="en">
<meta charset="UTF-8">
<link type="text/css" rel="stylesheet" href="bootstrap-3.2.0-dist\css\bootstrap.css"> <!--css file link in bootstrap folder-->
<title>View Users</title>
</head>
<style>
.login-panel {
margin-top: 150px;
}
.table {
margin-top: 50px;
}
</style>
<body>
<div class="table-scrol">
<h1 align="center">All the Users</h1>
<div class="table-responsive"><!--this is used for responsive display in mobile and other devices-->
<table class="table table-bordered table-hover table-striped" style="table-layout: fixed">
<thead>
<tr>
<th>User Id</th>
<th>User Name</th>
<th>User E-mail</th>
<th>User Pass</th>
<th>Action</th>
</tr>
</thead>
<?php
include("database/db_conection.php");
$view_users_query="select * from users";//select query for viewing users.
$run=mysqli_query($dbcon,$view_users_query);//here run the sql query.
while($row=mysqli_fetch_array($run))//while look to fetch the result and store in a array $row.
{
$user_id=$row[0];
$user_name=$row[1];
$user_email=$row[2];
$user_pass=$row[3];
?>
<tr>
<!--here showing results in the table -->
<td><?php echo $user_id; ?></td>
<td><?php echo $user_name; ?></td>
<td><?php echo $user_email; ?></td>
<td><?php echo $user_pass; ?></td>
<td> <button type="button" class="btn btn-primary">Edit</button>
<a href="delete.php?del=<?php echo $user_id ?>" onclick="return confirm('Are you sure?')"><button class="btn btn-danger">Delete</button></a></td>
</tr>
<?php } ?>
</table>
</div>
</div>
</body>
</html>
對不起它不是一個很好的答案,但希望你的想法。 – Kaiwen