用PHP编程测试潜在的实习

Creating a test PHP form that is supposed to take only one input, a date entered by user. Using a provided array of all states in US (contains all states and, for each, the number of days to ship to that state), am to insert into MySQL database for EACH STATE (I'm using a foreach loop): the state, user's input date, number of days to ship, and arrival date (determined by adding days to ship to input date). Finally, I need to display the database table of ALL states in HTML upon submission of form.

I think I'm on the right track here, but don't know how to test if it works, since I'm not using a real database.

Is it OK to put SQL insert query inside of my foreach loop? If not, how else can I get the four columns of data for each state?

Please let me know if this is correct. I'm not very experienced in PHP.

    <!DOCTYPE html>
<html>
<head>
<title>Determining Package Arrival Date</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Inconsolata" rel="stylesheet">
<style>
body {
    text-align: center;
    font-family: 'Inconsolata', monospace;
    font-size: 20px;
    text-align: center;
    background: #065E6A;
    color: white;
    width: 100vw;
    height: 100vh;
}
h1 {
    font-size: 30px;
    margin: 10px;
    padding: 10px;
}
form {
    padding: 25px;
}
input {
    border-radius: 10px;
    font-size: 15px;
    background: white;
    color: #065E6A;
    padding: 5px;
}
</style>
</head>
<body>
    <h1>Determine Your Package's Arrival Date</h1>
    <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
      <label>Date: <input type="date" name="date" /></label>
      <input type="submit" value="Submit" />
    </form>
    <br>
    <table class="striped">
            <tr class="header">
                <td>State</td>
                <td>Leaves on</td>
                <td>Days in Transit</td>
                <td>Arrives on</td>
            </tr>

            <?php
               while ($row = mysql_fetch_array($result)) {
                   echo "<tr>";
                   echo "<td>".$row[state]."</td>";
                   echo "<td>".$row[chosen_date]."</td>";
                   echo "<td>".$row[days_in_transit]."</td>";
                   echo "<td>".$row[arrival_date]."</td>";
                   echo "</tr>";
               }
            ?>
        </table>
<?php

// Check that form has been submitted
if (count($_POST)>0) {

    /* Attempt MySQL server connection, assuming you are running MySQL server with default setting (user 'root' with no password) */
    $server = mysql_connect("localhost", "root", "");

    // Check connection
    if($server === false){
        die("ERROR: Could not connect. " . mysql_connect_error());
    }

    // Create table
    $sql_table = "CREATE TABLE transit_check_log (
    ID BIGINT(6) UNSIGNED AUTO_INCREMENT, 
    state VARCHAR(128),
    chosen_date VARCHAR(128),
    days_in_transit VARCHAR(128),
    arrival_date VARCHAR(128),
    ip_address VARCHAR(128)
    )";

    $chosen_date = $_POST['date'];
    $ip_address = $_SERVER['REMOTE_ADDR'];
    //$details = json_decode(file_get_contents("http://ipinfo.io/{$ip_address}/json"));
    //$state =  $details->region;

    $states = Array(
        'Colorado'          => 3,
        'Alaska'            => 7,
        'Kansas'            => 4,
        'Arizona'           => 5,
        'California'        => 6,
        'Delaware'          => 2,
        'Illinois'          => 2,
        'Massachusetts'     => 1,
        'North Carolina'    => 3,
        'North Dakota'      => 4,
        'Utah'              => 4,
        'Virginia'          => 2,
        'Vermont'           => 1,
        'West Virginia'     => 2,
        'Wyoming'           => 4,
        'Nebraska'          => 4,
        'Connecticut'       => 1,
        'Washington, DC'    => 2,
        'Montana'           => 4,
        'Mississippi'       => 3,
        'New Mexico'        => 4,
        'Florida'           => 3,
        'Georgia'           => 3,
        'Hawaii'            => 6,
        'New York'          => 1,
        'Ohio'              => 2,
        'Oklahoma'          => 3,
        'Oregon'            => 5,
        'Washington'        => 5,
        'Wisconsin'         => 2,
        'Pennsylvania'      => 1,
        'Rhode Island'      => 1,
        'Alabama'           => 2,
        'Arkansas'          => 3,
        'South Carolina'    => 2,
        'South Dakota'      => 3,
        'Maryland'          => 2,
        'Iowa'              => 4,
        'Indiana'           => 3,
        'Kentucky'          => 3,
        'Louisiana'         => 3,
        'Idaho'             => 4,
        'Tennessee'         => 2,
        'Maine'             => 2,
        'Michigan'          => 3,
        'Minnesota'         => 3,
        'Texas'             => 4,
        'New Hampshire'     => 1,
        'New Jersey'        => 1,
        'Missouri'          => 3,
        'Nevada'            => 5
    );

    foreach( $states as $key => $value ){

        $state = $key;
        $arrival_date = date('Y-m-d', strtotime($chosen_date. " + {$value} days"));
        $days_in_transit = $value;

        // Attempt insert query execution
        $sql = "INSERT INTO transit_check_log (state, chosen_date, days_in_transit, arrival_date, ip_address) VALUES ('$state', '$chosen_date', '$days_in_transit', '$arrival_date', '$ip_address')";

        if(mysql_query($server, $sql)){
            echo "Records inserted successfully.";
        } else{
            echo "ERROR: Could not able to execute $sql. " . mysql_error($server);
        }

    }

    // Pull data from MySQL
    $result = mysql_query("SELECT * FROM transit_check_log");

    $row = mysql_fetch_array($result);

    // Close connection
    //mysql_close($server);

}
// End check that form submitted
?>

</body>
</html>