PHP Code How To Delete Data From MySQL Database By Id Using MySQLI

Php Code To Delete Row From Mysql Database Table Using MySQLI .


________________________________________________________

In this Php Tutorial we will Learn How To Delete MySQL Database Table Row By Id In Php  using  MySQLI .
I Use In This Tutorial:
- NetBeans IDE .
- XAMPP .
- PhpMyAdmin .


 




Php Source Code:


<?php

// php code to Delete data from mysql database 

if(isset($_POST['delete']))
{
    $hostname = "localhost";
    $username = "root";
    $password = "";
    $databaseName = "test_db";
    
    // get id to delete
    $id = $_POST['id'];
    
    // connect to mysql
    $connect = mysqli_connect($hostname, $username, $password, $databaseName);
    
    // mysql delete query 
    $query = "DELETE FROM `users` WHERE `id` = $id";
    
    $result = mysqli_query($connect, $query);
    
    if($result)
    {
        echo 'Data Deleted';
    }else{
        echo 'Data Not Deleted';
    }
    mysqli_close($connect);
}

?>

<!DOCTYPE html>

<html>

    <head>

        <title> PHP DELETE DATA </title>

        <meta charset="UTF-8">

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

    </head>

    <body>

        <form action="php_delete_data_from_mysql_database.php" method="post">

            ID TO DELETE:&nbsp;<input type="text" name="id" required><br><br>

            <input type="submit" name="delete" value="Clear Data">

        </form>

    </body>

</html>


///////////////OUTPUT:



                     
php delete mysql mysqli
Php Delete




Share this

Related Posts

Previous
Next Post »

1 comments:

comments
2 février 2023 à 07:12 delete

:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s
:-s

Reply
avatar