PHP MySQL Update Data

Update data in mysql using php

We already know how to establish connection between PHP web application and MySQL database system in our previous PHP tutorial. we also learnt to  select data from mysql and insert data into mysql database.

Now, In this PHP tutorial we will learn how to update data into MySQL database using PHP script.

UPDATE Statement

The UPDATE Statement is used to modify the records of existing table.

UPDATE Statement Syntax

UPDATE table_name SET  col1=val1, col2=val2, col3=val3 WHERE Condition

col1, col2 – is the anme of columns which records has to be updated.
val1, val2 – is the values of new records which has be updated in to table.

learn more about mysql UPDATE statement : UPDATE Statement

PHP Example of Update data in MySQL database


$username = "username";
$password = "password";
$hostname = "localhost"; 

//connection to the mysql database,
$dbhandle = mysqli_connect($hostname, $username, $password,$database);

if(mysqli_query($dbhandle, "Update StudentMst set Name='Vaidehi', City='Jaipur' where ID=4"))
echo "Record Updated Successfully";
echo "Error!!";

//close the connection



Leave a Reply

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