PHP database operation to modify user information
In real background management, administrators can modify a lot of user information. If the permissions are opened, the administrator can even modify the user's user name and other information.
In real operations, it is often:
Select the user to be modified
1. We can pass the user's ID in get to get the user information. Use SQL statements to query user information.
update.php modify the operation user data
Actually, we can only change the user's password. There are two situations:
Get the user ID and password
We need to obtain the user ID during the implementation process. Otherwise, when the update statement is generated, all the data in the entire table will be modified without the where condition.Passwords were previously stored using md5. Therefore, if the user changes the password, the password should also be stored in md5.
$id = (int)$_GET['id']; $password = md5(trim($_POST['password']));
Generate SQL statement
Put the user ID and password into the modified SQL statement and send it to the MySQL server for execution. That is, the operation of changing the password is completed.
$sql = "update user set password='" . $password . "' where id = $id"; $result = mysqli_query($conn, $sql); if ($result) { echo '修改成功'; }
Overall representation demonstration
Source code for displaying user information in the form
Update.php modified source code