Home > DeveloperSection > Beginner > Updating and Deleting Record in MySQL Database Table using PHP

Updating and Deleting Record in MySQL Database Table using PHP


PHP PHP 
Ratings:
1 Comment(s)
 5718  View(s)
Rate this:

Updating and Deleting Record in MySQL Database Table using PHP

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:

Updating and Deleting Record in MySQL Database Table using PHP

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.

Updating and Deleting Record in MySQL Database Table using PHP

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:

Updating and Deleting Record in MySQL Database Table using PHP

Now look ‘tblTemp’ table records.

Updating and Deleting Record in MySQL Database Table using PHP


select Cobobox

By Horas Panjaitan on   2 years ago
I have 2 table 
table province 
id_province  int auto encrypt
province name varchar (50) 


regency table 
id_regency int 
regency_name varchar (70) 
id_province int 

my question 



when i select the combo provinsi_nama then, that appears in the combobox regency_name is regency of the province's name.

Don't want to miss updates? Please click the below button!

Follow MindStick