What is the potential issue with the PHP script that is causing a blank database entry on each page reload?

The potential issue with the PHP script causing a blank database entry on each page reload is that the database insertion query is being executed every time the page is loaded, even if the form data is not submitted. To solve this issue, you can check if the form data has been submitted before executing the database insertion query.

<?php
if($_SERVER["REQUEST_METHOD"] == "POST") {
    // Process form data and insert into database
    // Replace the following lines with your actual database insertion code
    $servername = "localhost";
    $username = "username";
    $password = "password";
    $dbname = "database";

    $conn = new mysqli($servername, $username, $password, $dbname);

    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

    $sql = "INSERT INTO your_table_name (column1, column2, column3) VALUES ('value1', 'value2', 'value3')";

    if ($conn->query($sql) === TRUE) {
        echo "New record created successfully";
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }

    $conn->close();
}
?>