//connect to database require 'connection.php'; ?> <?php //insert make into database if (!empty($_POST)) { if (validateMake()) { $make = $_POST["make"]; $sql = $conn->prepare('INSERT INTO makes(Make) VALUE (?)'); $sql->bind_param("s", $make); if (!$sql->execute()) { failUpdate(); } } else { failUpdate(); } } function failUpdate() { echo '<script type="text/javascript">alert("Add Make Failed");</script>'; } function validateMake() { if (!isset($_POST["make"])) { return false; } return true; } ?>
} if ($check) { if (validateUpdate($row)) { $street = $_POST["street_" . $row["ID"]]; $city = $_POST["city_" . $row["ID"]]; $state = $_POST["state_" . $row["ID"]]; $zip = $_POST["zip_" . $row["ID"]]; $zip = $zip == null || $zip == '' ? null : $zip; $sql = $conn->prepare('UPDATE locations SET Street=?, City=?, State=?, ZIP=? WHERE ID=?'); $sql->bind_param('sssii', $street, $city, $state, $zip, $row["ID"]); if (!$sql->execute()) { failUpdate(2); } } else { failUpdate(3); } } } } function failUpdate($num) { echo '<script>console.error("update failed (' . $num . ')");</script>'; } function validateUpdate($row) { $state = $_POST["state_" . $row["ID"]]; if (!isset($state)) { return false; } $states = ["AL", "MT", "AK", "NE", "AZ", "NV", "AR", "NH", "CA", "NJ", "CO", "NM", "CT", "NY", "DE", "NC", "FL", "ND", "GA", "OH", "HI", "OK", "ID", "OR", "IL", "PA", "IN", "RI", "IA", "SC", "KS", "SD", "KY", "TN", "LA", "TX", "ME", "UT", "MD", "VT", "MA", "VA", "MI", "WA", "MN", "WV", "MS", "WI", "MO", "WY"];