Home >>MySQL Tutorial >PHP MySQL Update

PHP MySQL Update

PHP MySQL Update Query

The update keyword is basically used to modify or edit the existing records in the database table. it usually need a where clause to find out in which record change is to be done. It is must to specify the where clause otherwise all records of that table got modify. Syntax
UPDATE table_name SET column1=value1,column2=value2... WHERE column = value 
Note : Notice the WHERE clause in the UPDATE syntax is must otherwise all records will be updated! Ex Previous records in empInfo table are:
Emp_id Name Email Mobile
1 devesh [email protected] 9910099100
2 deepak [email protected] 9210053520
3 ravi [email protected] 9810098100
This example updates some data in the "empInfo" table
 <?php
//connect database 
$con=mysqli_connect("localhost","root","","Employee") or die(mysqli_error());

//update values of empInfo table
$data="UPDATE empInfo SET name='dev',mobile=9015501256 WHERE email='[email protected]'";
mysqli_query($con,$data);			
?>
In the above example , empInfo table has 3 records of devesh,deepak, and ravi. we need updation in this table as devesh change to dev and his mobile number also need to be changed. here first we create connection with the database,then database is selected using mysql_select_db(), then update query is passed to the mysql_query( ) and the database table is updated.

No Sidebar ads