There may be Requirement to
change the data in database some time. You can change the data in database
using update command in MySQL. The syntax is given below.
Syntax:
Update table_name SET field1
= new value1, field2 = new value2 where [condition]
- You can update one or more field together .
- You can update a single table at a one time.
- You can specify any condition using WHERE clause.
The WHERE clause is very
useful when you want to update selected rows in a table. You can use SQL UPDATE
command with or without WHERE Clause into PHP function mysql_query.
Example:
<?php
$con=mysql_connect(“localhost”,
“deep “, 12345);
if (!$con)
{
die(“could not be connect the
database” . mysql_error());
}
echo “ connected successfully
“;
mysql_select_db ( “student”);
$sql = ”UPDATE stu SET
stu_name =’Rakesh Kumar’ Where Id = 4;
$retrive =mysql_query ($sql,
$con );
If (!$retrive)
{
die (“could not be Update
data ”);
}
echo “update data
successfully “;
mysql_close ($con);
?>