💻 Source Code for delete.php

<?php
$host = 'localhost';
$user = 'ahmeuesz_dino';
$pwd = pwd***';
$db = 'ahmeuesz_myapp';
$conn = mysqli_connect($host, $user, $pwd, $db);

if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

if (isset($_GET['id'])) {
    $id = $_GET['id'];
    $del = "DELETE FROM enter WHERE id = $id";
    mysqli_query($conn, $del);
    header('Location:' . $_SERVER['PHP_SELF']);
    exit();
}

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $contact = $_POST['contact'];

    $sql = "INSERT INTO enter (name, email, contact) VALUES ('$name', '$email', '$contact')";
    mysqli_query($conn, $sql);

    header('Location:' . $_SERVER['PHP_SELF']);
    exit();
}

$sel = 'SELECT * FROM enter';
$result = mysqli_query($conn, $sel);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>✨ Registration Form</title>
    <link rel="stylesheet" href="style.css">
    <link rel="stylesheet" href="youtube.css">
</head>
<body>
    <div class="container">
        <h2 class="page-title">🌸 Registration Form</h2>

        <form action="" method="post" class="reg-form">
            <div class="input-group">
                <label>Name</label>
                <input type="text" name="name" placeholder="Enter your name" required>
            </div>

            <div class="input-group">
                <label>Email</label>
                <input type="email" name="email" placeholder="Enter your email" required>
            </div>

            <div class="input-group">
                <label>Contact</label>
                <input type="number" name="contact" placeholder="Enter contact number" required>
            </div>

            <input type="submit" value="Submit" class="btn btn-submit">
        </form>

        <div class="table-wrap">
            <table class="data-table">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>NAME</th>
                        <th>EMAIL</th>
                        <th>CONTACT</th>
                        <th>ACTION</th>
                    </tr>
                </thead>
                <tbody>
                    <?php while ($row = mysqli_fetch_array($result)) { ?>
                        <tr>
                            <td><?php echo $row['id']; ?></td>
                            <td><?php echo $row['name']; ?></td>
                            <td><?php echo $row['email']; ?></td>
                            <td><?php echo $row['contact']; ?></td>
                            <td>
                                <a href="?id=<?php echo $row['id']; ?>" class="btn btn-del">Delete</a>
                            </td>
                        </tr>
                    <?php } ?>
                </tbody>
            </table>
        </div>

        <div class="controls">
            <a href="showcode.php?file=delete.php" class="btn showcode-btn">💻 Show Code</a>
        </div>

        <?php include 'youtube.php'; ?>
    </div>
</body>
</html>
Back to Home