Updating Record:
UPDATE statement is used for update existing records in MySQL database table.
Syntax:
UPDATE table_name SET column_name1 = value1, column_name2 = value2,..... WHERE column_name = column_value
Note: WHERE clause specifies which record or records that should be updated. If you omit the WHERE clause, all records will be updated.
Example:
<?php
// create connection
$con = mysql_connect("localhost", "root", "root");
// check connection is created or not
if(!$con)
{
die ("Conection not created. Please try again !");
}
// select database
mysql_select_db('tempdatabase',$con);
// update query
$qry ="Update tblTemp set EmailId = 'username@hostname.com' where id = 102";
// execute the queryand check updation
if(mysql_query($qry))
{
echo 'Data updated successfully';
}
else
{
echo 'Updation failed' ;
}
?>
Output:
Deleting Record:
DELETE FROM statement is used to delete records from database table.
Syntax:
DELETE FROM tbl_Name WHERE column_name= value
Example:
Look at the following ‘tblTemp’ table.
Now we want to delete record from ‘tblTemp’ table where id is103. Let’s have an example to performing this action.
<?php
// create connection
$con = mysql_connect("localhost", "root", "root");
// check connection is created or not
if(!$con)
{
die ("Conection not created. Please try again !");
}
// select database
mysql_select_db('tempdatabase',$con);
// Delete query
$qry ="Delete from tblTemp where id =103";
// execute the queryand check updation
if(mysql_query($qry))
{
echo 'Record deleted successfully';
}
else
{
echo 'Record could not deleted.' ;
}
?>
Note: WHERE clause specifies which record or records that should be deleted. If you omit the WHERE clause, all records will be deleted from given table.
Output:
Now look ‘tblTemp’ table records.
Horas Panjaitan
20-Oct-2014table province
regency table
my question