filling a php form always ends up on a blank page, never adds information into the database

I am trying to insert data submitted in a form, into a MySQL Database, and I can’t see the problem in my code. Each time i try to insert it it ends up on a white page and the database remains empty.

this is the html form

<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Registro para el sorteo</title>
</head>
<body>
    <h1>Registro para el sorteo</h1>
    <form action="register.php" method="post">
        <label for="email">Email:</label>
        <input type="email" id="email" name="email" required><br><br>

        <label for="nombre">Nombre:</label>
        <input type="text" id="nombre" name="nombre" maxlength="20" required><br><br>

        <label for="apellidos">Apellidos:</label>
        <input type="text" id="apellidos" name="apellidos" maxlength="30" required><br><br>

        <label for="fecha_nacimiento">Fecha de nacimiento:</label>
        <input type="date" id="fecha_nacimiento" name="fecha_nacimiento" required><br><br>

        <label for="telefono">Teléfono:</label>
        <input type="text" id="telefono" name="telefono" maxlength="9" required pattern="d{9}"><br><br>

        <label for="color_preferido">Color preferido:</label>
        <input type="color" id="color_preferido" name="color_preferido" required><br><br>

        <label for="numero">Número para el sorteo (0-999):</label>
        <input type="number" id="numero" name="numero" min="0" max="999" required><br><br>

        <input type="submit" value="Registrar">
    </form>
</body>
</html>

And this the php part of the registration

<?php
$servername = "localhost";
$username = "root";
$password = "root"; 
$dbname = "sorteo";


$conn = new mysqli($localhost, $root, $root, $sorteo);


if ($conn->connect_error) {
    die("Conexión fallida: " . $conn->connect_error);
}


$email = $_POST['email'];
$nombre = $_POST['nombre'];
$apellidos = $_POST['apellidos'];
$fecha_nacimiento = $_POST['fecha_nacimiento'];
$telefono = $_POST['telefono'];
$color_preferido = $_POST['color_preferido'];
$numero = $_POST['numero'];

$fecha_actual = new DateTime();
$fecha_nacimiento_dt = new DateTime($fecha_nacimiento);
$edad = $fecha_actual->diff($fecha_nacimiento_dt)->y;

if ($edad < 18) {
    die("Debes ser mayor de edad para participar en el sorteo.");
}


$sql = "INSERT INTO participantes (email, nombre, apellidos, fecha_nacimiento, telefono, color_preferido, numero) 
        VALUES ('$email', '$nombre', '$apellidos', '$fecha_nacimiento', '$telefono', '$color_preferido', '$numero')";

if ($conn->query($sql) === TRUE) {
    echo "Registro exitoso. <a href='participants.php'>Ver participantes</a>";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();

ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
?>

This a list to delete, update or obtain the list of participants

<?php
$servername = "localhost";
$username = "root";
$password = ""; 
$dbname = "sorteo";


$conn = new mysqli($localhost, $root, $root, $sorteo);


if ($conn->connect_error) {
    die("Conexión fallida: " . $conn->connect_error);
}

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

        $email = $_POST['email'];
        $sql = "DELETE FROM participantes WHERE email='$email'";
        $conn->query($sql);
    } elseif (isset($_POST['update'])) {
      
        $email = $_POST['email'];
        $nombre = $_POST['nombre'];
        $apellidos = $_POST['apellidos'];
        $fecha_nacimiento = $_POST['fecha_nacimiento'];
        $telefono = $_POST['telefono'];
        $color_preferido = $_POST['color_preferido'];
        $sql = "UPDATE participantes SET nombre='$nombre', apellidos='$apellidos', fecha_nacimiento='$fecha_nacimiento', telefono='$telefono', color_preferido='$color_preferido' WHERE email='$email'";
        $conn->query($sql);
    }
}


$sql = "SELECT * FROM participantes";
$result = $conn->query($sql);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Lista de Participantes</title>
</head>
<body>
    <h1>Lista de Participantes</h1>
    <table border="1">
        <tr>
            <th>Email</th>
            <th>Nombre</th>
            <th>Apellidos</th>
            <th>Fecha de Nacimiento</th>
            <th>Teléfono</th>
            <th>Color Preferido</th>
            <th>Número</th>
            <th>Acciones</th>
        </tr>
        <?php
        if ($result->num_rows > 0) {
            while($row = $result->fetch_assoc()) {
                echo "<tr>";
                echo "<form method='post' action='participants.php'>";
                echo "<td><input type='hidden' name='email' value='" . $row['email'] . "'>" . $row['email'] . "</td>";
                echo "<td><input type='text' name='nombre' value='" . $row['nombre'] . "'></td>";
                echo "<td><input type='text' name='apellidos' value='" . $row['apellidos'] . "'></td>";
                echo "<td><input type='date' name='fecha_nacimiento' value='" . $row['fecha_nacimiento'] . "'></td>";
                echo "<td><input type='text' name='telefono' value='" . $row['telefono'] . "'></td>";
                echo "<td><input type='color' name='color_preferido' value='" . $row['color_preferido'] . "'></td>";
                echo "<td>" . $row['numero'] . "</td>";
                echo "<td><button type='submit' name='update'>Actualizar</button> <button type='submit' name='delete'>Eliminar</button></td>";
                echo "</form>";
                echo "</tr>";
            }
        } else {
            echo "<tr><td colspan='8'>No hay participantes registrados.</td></tr>";
        }
        ?>
    </table>
</body>
</html>

<?php
$conn->close();

ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
?>

And the sql code

CREATE DATABASE sorteo;
USE sorteo;

CREATE TABLE participantes (
    email VARCHAR(50) PRIMARY KEY,
    nombre VARCHAR(20) NOT NULL,
    apellidos VARCHAR(30) NOT NULL,
    fecha_nacimiento DATE NOT NULL,
    telefono VARCHAR(9) NOT NULL,
    color_preferido VARCHAR(7) NOT NULL,
    numero INT NOT NULL
);

As i said i tried to make it so when the form is filled the data adds to the database on mysql

New contributor

somedudewithlizards is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật