How to Insert and Edit Data in phpMyAdmin | CRUD Operations
# CHAPTER 6
Inserting, Editing, and Deleting Data
1. Introduction
A database is useless if it is empty. In backend programming, the four foundational actions you perform on data are known as CRUD: Create, Read, Update, and Delete. In raw SQL, these require typing outINSERT INTO, SELECT, UPDATE, and DELETE FROM queries. But what if a non-technical manager just needs to quickly fix a typo in a customer's name? phpMyAdmin provides a beautiful, spreadsheet-like interface to perform all of these actions with simple clicks.
2. Learning Objectives
By the end of this chapter, you will be able to:- Access the Browse tab to read (view) data.
- Use the Insert tab to add new records.
- Edit existing rows directly from the grid.
- Delete individual or bulk records safely.
- Understand the role of Auto-Increment during data entry.
3. Reading Data: The Browse Tab
To view the data inside a table:-
1.
Click the specific table (e.g.,
users) in the left sidebar.
- 2. The main screen automatically defaults to the Browse tab at the top.
- 3. You will see a visual grid containing your data. It looks exactly like an Excel spreadsheet.
- 4. If your table has 1,000 rows, phpMyAdmin automatically paginates it (showing 25 rows per page) so your browser doesn't crash. You can navigate pages using the arrows above the grid.
*Note: If the table is completely empty, the Browse tab might be grayed out, or it will display a message saying "MySQL returned an empty result set (i.e. zero rows)."*
4. Creating Data: The Insert Tab
Let's add a new user to the database!-
1.
With the
userstable selected, click the Insert tab at the top of the screen.
-
2.
You will see a form listing all the columns in your table (
id,username,email).
-
3.
The
idfield: Leave this completely blank! Because we set this column to Auto-Increment (A_I) in the previous chapter, MySQL will automatically generate the ID number for us.
-
4.
The
usernamefield: Typejohndoe.
-
5.
The
emailfield: Typejohn@example.com.
- 6. At the bottom of the form, click Go.
*Result: phpMyAdmin flashes a green success message: "1 row inserted." It also shows you the raw INSERT INTO users... SQL code it generated to perform the action!*
5. Updating Data: The Edit Button
John Doe calls support. He misspelled his email address. Let's fix it.- 1. Go back to the Browse tab.
- 2. Find John Doe's row in the grid.
- 3. Look at the options on the far left of the row. Click the Edit button (pencil icon).
- 4. The screen changes back to a form pre-filled with John's data.
-
5.
Change the email to
john.doe@example.com.
- 6. Click Go.
*Pro Tip:* In modern versions of phpMyAdmin, you can just double-click directly on the text inside the grid on the Browse tab, type the correction, and hit Enter. It saves instantly!
6. Deleting Data: The Delete Button
John Doe cancels his account. We must remove him from the database.- 1. In the Browse tab, find John's row.
- 2. Click the Delete button (red minus icon) on the left side of his row.
- 3. phpMyAdmin will ask for confirmation: "Do you really want to execute DELETE FROM users WHERE id = 1?"
- 4. Click OK. John is gone.
7. Bulk Operations
What if 50 spam accounts register simultaneously? You don't want to click "Delete" 50 individual times.- 1. In the Browse tab, you will notice a small checkbox next to every single row on the left side.
- 2. Check the boxes next to the 50 spam accounts. (You can also click "Check all" at the bottom).
- 3. Below the grid, look for the "With selected:" menu.
- 4. Click Delete. Confirm the action. All 50 rows are wiped out in one click.
8. Mini Project: Employee Management
Scenario: You are the HR manager. You need to populate anemployees table.
- 1. Go to the Insert tab. Notice how there are *two* empty forms stacked on top of each other? phpMyAdmin allows you to insert two rows at the same time!
-
2.
Fill out the top form for "Alice". Fill out the bottom form for "Bob". Leave their
ids blank. Click Go.
- 3. Go to the Browse tab. Verify both employees are there.
- 4. Double-click Alice's salary directly in the grid to give her a raise. Press Enter.
- 5. Check Bob's checkbox and click Delete to terminate his record.
9. Common Mistakes
-
Manually typing Auto-Increment IDs: A common beginner mistake is trying to guess what the next
idnumber should be and typing it into the Insert form manually (e.g., typing5because there are 4 rows). If you guess wrong, or if row 5 already exists, MySQL throws a fatal error. Always leave Auto-Increment fields completely blank during insertion.
10. Best Practices
- Never Use phpMyAdmin for Massive Data Entry: phpMyAdmin is fantastic for fixing typos or inserting 5 test users. If you need to insert 10,000 products, do not use the Insert tab. Use the Export/Import tab (Chapter 8) to upload an Excel/CSV file!
11. Exercises
- 1. What does the acronym CRUD stand for in database management?
- 2. Which tab must you select to view a spreadsheet-like grid of your data?
12. Database Challenges
You want to insert a new row into theorders table. One of the columns is order_date (Data Type: TIMESTAMP). You want the date to be the exact current moment in time, but you don't want to look at a clock and type it manually. How do you tell phpMyAdmin to do this automatically on the Insert screen?
*(Answer: On the Insert form, look at the "Function" dropdown menu next to the order_date field. Select CURRENT_TIMESTAMP. MySQL will automatically inject the exact server time when you click Go).*
13. MCQ Quiz with Answers
When utilizing the "Insert" tab in phpMyAdmin to add a new record, what is the required workflow for a Primary Key column that has the Auto-Increment (A_I) attribute enabled?
To quickly fix a typo in a user's email address without writing an SQL UPDATE statement, what is the most efficient workflow in the phpMyAdmin interface?
14. Interview Questions
- Q: Explain how phpMyAdmin translates visual GUI actions (like clicking the "Delete" button next to a row) into raw SQL commands behind the scenes.
- Q: A non-technical user asks you how to bulk delete 500 obsolete records without using a terminal. Describe the exact step-by-step workflow using the phpMyAdmin Browse tab.