PHP MySQL Update Data

✏️ PHP MySQL Update Data Tutorial

The UPDATE statement is used to modify existing records in a MySQL table. You can update one or more columns and filter which rows to update using the WHERE clause.

⚠️ Without a WHERE clause, all rows will be updated.


1️⃣ Using mysqli (Procedural)


 

✅ Updates the age of the user named Vipul to 29.


2️⃣ Using mysqli Object-Oriented


 

$conn->query() executes the SQL statement in object-oriented style.


3️⃣ Using PDO with Prepared Statements


 

✅ Using prepared statements prevents SQL injection and allows dynamic updates.


4️⃣ Update Multiple Columns


 

  • Updates name, age, and email for a specific record.


5️⃣ Key Points

  1. Use UPDATE table_name SET column=value to modify data.

  2. Always include a WHERE clause to avoid updating all rows.

  3. Prepared statements are safer for user input.

  4. Can update single or multiple columns at once.

  5. Check for errors using mysqli_error(), $conn->error, or PDOException.

CodeCapsule

Sanjit Sinha — Web Developer | PHP • Laravel • CodeIgniter • MySQL • Bootstrap Founder, CodeCapsule — Student projects & practical coding guides. Email: info@codecapsule.in • Website: CodeCapsule.in

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *