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);

?>

Week3 - Michael Porter

Current Users:

Address # First Name Last Name Street City State Zip

value=""

name="address_no">

value=""

name="address_no">

Enter your first name:

value="">

Enter your last name:

value="">

Enter your street address:

value="">

Enter your city:

value="">

Enter your state:

value="">

Enter your zip code:

value="">

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!