Update mysql table data in php

Update mysql table`s data with php script.

In this tutorial of php we are going to update the data of existing table.

Query.

For update mysql data we use following query : UPDATE <table_name> set <field=’new_value’> where <field=’old_value’>

In my case i have a database named as mydatabse and there is a table in that database named as students_data , so from that table i want to update some data.

 

<?php
//creating connection.
$mycon = mysqli_connect('localhost','root','','mydatabase');
//testing connection.
if($mycon == true)
{
echo "Seccessfully connected.";
}
else
{
die('Problem with connection'.mysqli_connect_error());
}
//update query.
$query = "UPDATE students_data set name='Gaurav Mishra' where name='Gaurav'";
$res = mysqli_query($mycon,$query);
//testing query.
if($res == true)
{
echo "Query successfully executed. Data updated";
}
else
{
die("Problem in execution".mysqli_connect_error());
}
$mycon->close();
?>