Question: I need to take this code and break it up into three files, but have it run the same. Model - all database access and
I need to take this code and break it up into three files, but have it run the same.
Model - all database access and query information
View - all user interface information, with style information placed in a separate .css file
Controller - all functions needed to link the View and the Model
Here is the code. I'm working in Visual Studio Code.
//
$hostname = "localhost";
$username = "ecpi_user";
$password = "Password1";
$dbname = "cis224_file";
$conn = mysqli_connect($hostname, $username, $password, $dbname);
//
$addressNo = -1;
$firstName = "";
$lastName = "";
$street = "";
$city = "";
$states = "";
$zip = 0;
//
$add = false;
$edit = false;
$update = false;
$delete = false;
if (isset($_POST['address_no'])) {
$addressNo = $_POST['address_no'];
$add = isset($_POST['add']);
$update = isset($_POST['update']);
$edit = isset($_POST['edit']);
$delete = isset($_POST['delete']);
}
if ($add) {
//
$firstName = $_POST['fname'];
$lastName = $_POST['lname'];
$street = $_POST['street'];
$city = $_POST['city_1'];
$states = $_POST['state_1'];
$zip = $_POST['zip_1'];
$addQuery = "INSERT INTO
portermid (FirstName, LastName, Street, City, States, Zip)
VALUES ('$firstName', '$lastName', '$street', '$city', '$states', '$zip')";
mysqli_query($conn, $addQuery);
//
$addressNo = -1;
$firstName = "";
$lastName = "";
$street = "";
$city = "";
$states = "";
$zip = 0;
}
else if ($edit) {
//
$selQuery = "SELECT * FROM portermid WHERE AddressNo = $addressNo";
$result = mysqli_query($conn, $selQuery);
$userInfo = mysqli_fetch_assoc($result);
//
$firstName = $userInfo['FirstName'];
$lastName = $userInfo['LastName'];
$street = $userInfo['Street'];
$city = $userInfo['City'];
$states = $userInfo['States'];
$zip = $userInfo['Zip'];
}
else if ($update) {
//
$firstName = $_POST['fname'];
$lastName = $_POST['lname'];
$street = $_POST['street'];
$city = $_POST['city_1'];
$states = $_POST['state_1'];
$zip = $_POST['zip_1'];
$updQuery = "UPDATE portermid SET
FirstName = '$firstName', LastName = '$lastName',
Street = '$street', City = '$city', States = '$states', Zip = $zip
WHERE AddressNo = $addressNo";
mysqli_query($conn, $updQuery);
//
$addressNo = -1;
$firstName = "";
$lastName = "";
$street = "";
$city = "";
$states = "";
$zip = 0;
}
else if ($delete) {
//
$delQuery = "DELETE FROM portermid WHERE AddressNo = $addressNo";
mysqli_query($conn, $delQuery);
$userNo = -1;
}
//
$query = "SELECT * FROM portermid";
$result = mysqli_query($conn, $query);
?>
table {
border-spacing: 5px;
}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 15px;
text-align: center;
}
th {
background-color:lightskyblue;
}
tr:nth-child(even) {
background-color:whitesmoke;
}
tr:nth-child(odd) {
background-color:lightgray;
}
Current Users:
| Address # | First Name | Last Name | Street | City | State | Zip | ||
|---|---|---|---|---|---|---|---|---|
|
|
|
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
