I’m a programming student with a teacher that doesn’t really teach. She just reads pre-made powerpoint slides and often seems surprised to learn about things that she was unaware you could do prior to reading the slides. Basically, I think the school needed a PHP teacher and just kinda said “Eh. close enough. You’ll do.” She’s not really friendly and asking for help is usually met with a rude reply, a condescending tone and an answer that isn’t really an answer. I’ve asked classmates for help to no avail - they’re just as confused. There are literally no PHP tutors as it’s just a community college. I had the same lady for SQL and knew what to expect, but she’s the only professor for these classes. She’s an ex-marine, she’s probably in her 60s or so and is close to retiring so I kinda get the feeling that she doesn’t really care at this point, but it does a huge disservice to us - her students. I’ve never actually seen her code a single thing in class and she often gets confused and has to stop to thumb through her book or power points in order for her to figure out how to even import a database into xampp. So this is my last hope. My chosen major is programming, like OOP with VB and Java and such, but we’re still required to take PHP and SQL. I’m working on talking to the dean about the issues with the prof, but until something, if anything can be done, I have to deal with what’s at hand.
With that said, here my assignment specifications just so you all have an idea what I’m actually trying to do. Below I’ll post code showing what I’ve done so far. I’m very confused, very frustrated and struggling so much with this thing. Please understand, I’m not asking anyone to do my homework for me. I need help. I have some random code snippeds garnered from my book and the crap power-point, but I don’t understand how they work or where to put them or anything.
==============================================
INSTRUCTIONS
Deliverables: Zipped project folder containing the following files:Index.html containing a form
Main.css for formatting
Display_data.php to display the data retrieved from the database
Database_error.php to display error messagesIf necessary:
Use the SQL tab in PHPAdmin to write and run the following query:
CREATE DATABASE ZipcodeData
Use the Import tab to import the file zipcodes2014 to create the tables and import the data for the ZipcodeData database.Create an HTML file with a form that allows a user to enter a city and a two letter state abbreviation. Use POST and your display_data.php file.
Create a PHP file that will create and run a query against the zipcodes table. The query will retrieve the following columns from the table, for the city and state entered in the form:
Zipcode
Latitude
Longitude
Estimated populationTry/Catch must be used around the following pieces of code:
Creating the PDO object to connect to a database
Preparing, binding values and executing the queryEach Catch clause will assign a different appropriate message to a variable, and will then include the database_error.php file (which will display the error message) and exit display_data.php.
The HTML page created and returned by the PHP will contain the city and state as
headers. The PHP must display the four columns of data in a table. Because the number of rows to be returned may be different each time the code should use a foreach loop that will loop through the array returned by the query, creating a new row for the table and displaying the data for each iteration of the loop.
===========================================
MY HTML PAGE
Find Zipcode Data<h1>Zip code data by city and state</h1> <form action="Display_data.php" method="post">
<div id="data"> <label>City:</label> <input type="text" name="city"><br> <label>State (two letter abbreviation):</label> <input type="text" name="state"><br> </div>
<div id="buttons"> <label> </label> <input type="submit" value="Display Zipcodes"><br> <input type="reset" value="Clear Form"><br> </div> </form> </main>
==============================================
MY CSS PAGE
/*CSS for general page look*/ main { width: 450px; height: 190px; margin: 0 auto; padding: 1em; background: white; border: 2px solid navy; }body {
background-color: #fff;
font-family: Arial, Helvetica, sans-serif;
text-align: center
}/* Header */
h1 {
margin-top: 0;
color: navy;
}/CSS for label positioning/
label {
width: 12em;
float: left;
padding-bottom: .5em;
}/corresponds to div tag on index.html to adjust spacing around textboxes/
#data input {
float: left;
width: 11em;
margin-bottom: .5em;
}/corresponds to div tag on index.html to adjust spacing below buttons/
#buttons input {
margin-bottom: .5em;
left:50%;
}
===========================================
MY DISPLAY_DATA.PHP PAGE
[php]<?php
$city = $_POST[‘city’];
$state = $_POST[‘state’];
$dsn = ‘mysql:host=localhost;dbname=zipcodedata’;
$username = ‘mgs_user’;
$password = ‘pa55word’;
try {
$db = new PDO($dsn, $username, $password);
echo ‘
You are connected to the database!
’;} catch (PDOException $e) {
$error_message = $e->getMessage();
echo "
An error occurred while connecting to
the database: $error_message
exit();
}
// creates PDO object
$db = new PDO($dsn, $username, $password);
?>
Display zip code data</main>
[/php]
======================================
MY DATABASE_ERROR.PHP PAGE
[php]<?php
?>
Error</main>
[/php]
=================================================