Page 355 - Computer Software Application TP - Volume 1
P. 355
COMPUTER SOFTWARE APPLICATION - CITS
<head> HTML form </title>
</head>
<body>
<?php
// Database connection parameters
$servername = “localhost”; // Change this if MySQL server is on a different host
$username = “root”; // Change this to your MySQL username
$password = “”; // Change this to your MySQL password
$database = “mydb”; // Change this to your database name
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error)
{
die(“Connection failed: “ . $conn->connect_error);
}
// Check if the form is submitted
if ($_SERVER[“REQUEST_METHOD”] == “POST”)
{
// Get ID from the form
$username = $_POST[“username”];
// Prepare and execute the SQL statement to delete data from the table
$stmt = $conn->prepare(“DELETE FROM users WHERE username = ?”);
$stmt->bind_param(“s”, $username);
if ($stmt->execute())
{
echo “Record deleted successfully”;
}
else
{
echo “Error: “ . $conn->error;
}
// Close statement
$stmt->close();
}
// Close connection
$conn->close();
340
CITS : IT & ITES - Computer Software Application - Exercise 61