Wednesday, April 23, 2025

MySQLi Delete From Table

delete_from_table.php


<?php
//Config

$server = "localhost";
$user = "root";
$password = "";
$database = "address_book";

//Establishing a Connection to MySQL Server
$connection = mysqli_connect($server, $user, $password, $database);

//Check Connection
if (!$connection) {
	die("<h2>Total Fail</h2> " . mysqli_connect_error());
} else {
	echo "Connection Successfull <br>";
}

//SQL Command
$sql_command = "DELETE FROM people WHERE id=3";

if (mysqli_query($connection, $sql_command)) {
	echo "SQL Command OK";	
} else {
	echo "SQL Error " . mysqli_error($connection) ;
}

?>

This SQL command will delete a row from the people table in the database where the id value is equal to 3. If the SQL command is executed successfully, the message "SQL Command OK" will be displayed. If there is an error, the message "SQL Error" along with the error message will be displayed.

After we run script once for that specific ID:


Connection Successfull
SQL Command OK

No comments:

Post a Comment

Tkinter Introduction - Top Widget, Method, Button

First, let's make shure that our tkinter module is working ok with simple  for loop that will spawn 5 instances of blank Tk window .  ...