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
2. Modify the relevant content
##3. Execute the modified statement and generate a prompt
When making the user list page, we have completely shown you how to display the functions of editing users and deleting users in the list.
Click to select the user to be modified from the list. There should be a dedicated page to display the content that needs to be modified. We also showed it to you in the second picture above.
But how to put user information in when implementing the code?
edit.php displays user information
Implementation process:1. We can pass the user's ID in get to get the user information. Use SQL statements to query user information.
2. Assign the user’s information to the form. When the user clicks submit, we submit the value modified by the user in the form table in update.php. Because you need to specify which user to modify in the where condition modified in update. So, we put the user's ID in the input hidden form. When you click submit, the hidden ID will also be passed to the update page.
Usernames are usually not allowed to be modified. Therefore, I added a readonly parameter at the end of the username input form, and the username is not allowed to be modified.
The code is as follows:
update.php Modify operation user data
In fact, we can only modify the user's password. There are two situations:
1. The user changed the password
2. The user did not change the password
In fact, we can deceive the ordinary operators who do not understand the technology in front.
1. If he has not changed his password, give him a success message
2. If he has changed his password. When we actually change the user's password, it also prompts that the change was successful.
Get the user ID and password
We need to get 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
Next Section