[已编辑解决]
我有一个update.php文件来更改某个用户角色。我得到消息更新记录成功,但数据库表中没有更改。你能告诉我哪里错了吗。不过,我对php还不熟悉。
更新某个用户的用户名和用户角色。
更新.php
<?php
require 'dbconnect.php';
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$newUsername = mysqli_real_escape_string($conn, $_POST['username']);
$newRole = mysqli_real_escape_string($conn, $_POST['role-dropdown']);
$id = $_POST['id'];
$sql = "UPDATE users SET username = '$newUsername', user_role = '$newRole' WHERE userID = '$id';";
if($conn->query($sql) === TRUE)
{
echo("Record updates successfully");
}
else
{
echo("Error updating record: ");
die(mysqli_error($conn));
}
}
$conn->close();
?>
使用表单更改用户名和用户角色的网页
编辑\u user.php
<main>
<div id="gt-menu">
</div>
<form id="user-form" class="form" method="POST" action="includes/update.php">
<h3>Edit User Role</h3>
<label for="username">Username:</label>
<input id="username" type="text" name="username" value="<?php echo $row['username']; ?>">
<input type="hidden" name="id" value="<?php echo $row['userID']; ?>">
<select class="select" id="role-dropdown" name="role-dropdown">
<option value="_Any" selected="selected">Please Choose</option>
<option value="1">Admin</option>
<option value="2">Manager</option>
<option value="3">General User</option>
<option value="4">External Company</option>
</select>
<button type="submit" name="update-btn" id="update-btn">Update</button>
</form>
</main>
1条答案
按热度按时间xiozqbni1#
你的id没有值
应该是这样的: