PHP Basics

PHP MySQLi Update Records

In some cases, we may want to update table data using update sql statement. Lets see how can we update.

The table which I am using to update record is as below. The table name is emp_info

emp_id emp_name emp_age
1 Raj 22
2 Rahul 24
3 Vivek 26
4 Ajay 28
5 Suraj 29

In the above table, lets say, I want to update the emp_name from Vivek to Birju whose id is 3.

If you have understanding of mysqli insert statement then following code is just a piece of cake for you. I have already discussed about insert statement. So check that tutorial.

Update Record

$conn=mysqli_connect(‘localhost’,’root’,”,”employee_db);

$sql=”update emp_info set emp_name=’Birju’ where id=3″;

if(mysqli_query($conn,$sql)){

echo “Updated successfully”;

}else{

echo “Failed to Update”;

}

Output: Updated uccessfully