我想爲每個數據庫條目都有一個編輯按鈕,並且當用戶單擊編輯時,它只會獲得條目,這是它的一部分。我試圖使用隱藏的輸入,如<input type="hidden" name="userid" value=...>
,但我不知道該把它放在哪裏,以及它如何提供幫助。傳遞按鈕上的ID單擊,爲每個用戶
所以你也可以想象它,我附上了一張桌子的照片。
我希望你能幫助我,如果有,你需要知道的其他任何信息,只是讓我知道吧。
<?php
include 'dbConnect.php';
echo '<table border="1" cellpadding="1" cellspacing="1" width="90%" style="margin: 0 auto">';
echo '<tr class="allUsers">';
echo '<th>Username</th>';
echo '<th>First name</th>';
echo '<th>Last name</th>';
echo '<th>Email</th>';
echo '<th>Year group</th>';
echo '<th>Subject 1</th>';
echo '<th>Subject 2</th>';
echo "<th>Subject 1's teacher</th>";
echo "<th>Subject 2's teacher</th>";
echo '<th>Privilege</th>';
echo '<th></th>';
echo '</tr>';
$getUsers = mysqli_query($connection, "SELECT * FROM users");
while($users=mysqli_fetch_assoc($getUsers)){
echo '<form method="post" action="">';
echo '<tr>';
echo '<td>'.$users['username'].'</td>';
echo '<td>'.$users['first_name'].'</td>';
echo '<td>'.$users['last_name'].'</td>';
echo '<td>'.$users['email'].'</td>';
echo '<td>'.$users['year_group'].'</td>';
echo '<td>'.$users['subject'].'</td>';
echo '<td>'.$users['subject2'].'</td>';
echo '<td>'.$users['teacher'].'</td>';
echo '<td>'.$users['teacher2'].'</td>';
echo '<td>'.$users['is_admin'].'</td>';
echo '<td><button name="editUser">Edit</button></td>';
echo '</tr>';
echo '</form>';
}
if (isset($_POST['editUser'])){
$username = $_SESSION['name'];
// ....
}
}
echo '</table>';
?>
? – maximedubois
在同一頁面上,大概是通過隱藏其他條目,或者只是另一個頁面,如果更容易。 – leveeee