How can the code be modified to ensure that all three array values are successfully inserted into the database?

The issue is likely occurring because the SQL query is only inserting the first element of the array into the database. To ensure that all three array values are successfully inserted, you can use a loop to iterate through the array and execute the SQL query for each element.

<?php
// Establish a connection to the database
$connection = mysqli_connect("localhost", "username", "password", "database");

// Check connection
if (!$connection) {
    die("Connection failed: " . mysqli_connect_error());
}

// Sample array values
$array = [1, 2, 3];

// Loop through the array and insert each value into the database
foreach ($array as $value) {
    $sql = "INSERT INTO table_name (column_name) VALUES ('$value')";
    
    if (mysqli_query($connection, $sql)) {
        echo "Record inserted successfully<br>";
    } else {
        echo "Error inserting record: " . mysqli_error($connection) . "<br>";
    }
}

// Close the database connection
mysqli_close($connection);
?>