Delete Data From A MySQL Database Table

Delete Data From A MySQL Database Table

Delete Data From A MySQL Database Table

Delete  Data from  a MySQL Database Table, in this article i will step through how  to delete data from  MySQL Table.

Prior to that you need to complete  the items listed Below

  1. Mamp or xampp with phpMyAdmin install into your Computer , check out here
  2.  A Sample Database created Check out Here
  3.  New User Created . Check out Here
  4. A New table created , check out Here
  5. Insert Data into the Table Here
  6. Update Data into the Table Here

 

Step 1

Start your My SQL and Apache Server

mysql and Apache Initialised Success
mysql and Apache Initialised Success

 

Step 2

Start your My SQL and Apache Server

(1) First to connect to the Database

(2) Then  we Attempt to delete Data inside ” mytable”  which reside in ” janedb

 

<?php /* Declare User connecting Credential*/ $hostName ="localhost"; $userName ="jane"; $userPassword ="jane"; $database ="janedb"; /* return connection status through $dbConnectionStatus Boolean Variable*/ /* using mysqli Object*/ $dbConnectionStatus = new mysqli($hostName, $userName, $userPassword,$database); /* Check whether the User Succesfully connect to localhost and mydata Database*/ /* ->  Access the instance "$dbConnectionStatus" variable property "connect_error " boolean */

if ($dbConnectionStatus->connect_error){     

        
     die("Connection failed: " . $dbConnectionStatus->connect_error);

}
/* SQL Script to insert data */

   
	
	$sql ="DELETE FROM mytable where lastname='Ge'";
	
	$deleteData = $dbConnectionStatus -> query($sql);
  
  
  if ($deleteData) {
    echo "Data Deleted ";
     } else {
    echo "Error inserting data into table: " . $dbConnectionStatus->error;
	
          }

    $dbConnectionStatus->close();
	 
	 
	 
	 
   

?>


Step 3

Save this File as “.php” extension in

C:\xampp\htdocs

Step 4

Test it

(1)Click Admin

(2) Click the  PHP File you have just created  in this example i name it  ” deleteData.php”

 

Before Delete

 

before delete
before delete

After Delete

 

Data Deleted
Data Deleted

Leave a Reply

Your email address will not be published. Required fields are marked *

one × 5 =