Crude PHP
Crude PHP
Delete — that are typically performed on a database, often using MySQL. Below is a simple
example that demonstrates how to implement these operations in PHP.
USE crud_example;
<?php
$servername = "localhost";
$username = "root";
$password = "";
$database = "crud_example";
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
<?php
include 'db.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST['name'];
$email = $_POST['email'];
<form method="post">
Name: <input type="text" name="name" required><br>
Email: <input type="email" name="email" required><br>
<input type="submit" value="Add User">
</form>
<?php
include 'db.php';
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "ID: " . $row['id'] . " - Name: " . $row['name'] . " - Email: " .
$row['email'] . "<br>";
}
} else {
echo "No records found.";
}
?>
<?php
include 'db.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$id = $_POST['id'];
$name = $_POST['name'];
$email = $_POST['email'];
<form method="post">
ID: <input type="number" name="id" required><br>
Name: <input type="text" name="name" required><br>
Email: <input type="email" name="email" required><br>
<input type="submit" value="Update User">
</form>
<?php
include 'db.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$id = $_POST['id'];
<form method="post">
ID: <input type="number" name="id" required><br>
<input type="submit" value="Delete User">
</form>