Learn how to safely edit existing data in the database
UPDATE is the operation used to modify existing data in the database. It takes changes from a form and updates only the specific record without affecting other data.
UPDATE operations are used when you edit your profile, change your password, update a post, or modify any information you previously created.
READ the current student record from the database and display it in a form
User changes any fields they want to modify in the form
PHP checks: Are all fields valid? Is the email format correct? Is there a valid status?
Create a prepared statement with a WHERE clause to identify which record to update
Run the SQL UPDATE command to modify the specific record in the database
Show success message and redirect to the student list to show the changes
The form below shows how an UPDATE operation looks and feels (with current student data pre-filled). To actually update students in the database, you need to login to the admin panel.
âšī¸ Notice: The form shows existing student data (READ), user can edit it, then SUBMIT to UPDATE
| Aspect | CREATE | UPDATE |
|---|---|---|
| Purpose | Add new record | Modify existing record |
| SQL Used | INSERT | UPDATE ... WHERE |
| Pre-filled Data | No, form is empty | Yes, form shows current data |
| Result | New ID is generated | ID stays the same |
| Row Count | Database grows | Database size unchanged |
The WHERE clause identifies which specific record to update. Without it, ALL records would be updated!
We use prepared statements to prevent SQL injection even in UPDATE operations.
Now that you understand the UPDATE operation, explore the other operations: