Question: Milestone 2: create and populate a database table for baby names 6. Download the file containing the 1000 most popular baby names in 2014, according

Milestone 2: create and populate a database table for baby names 6. Download the file containing the 1000 most popular baby names in 2014, according to the Social Security Administration office: https://www.ssa.gov/oact/babynames/names.zip. 7. Expand the zip file and look for the file named yob2014.txt. 8. Upload that file to your area on the server. 9. Write a PHP script to: o Connect to the database o Create a table (BABYNAMES) for storing the most popular baby names o Populate the table using the raw content from yob2014.txt. o Display the tables contents on a web page.

Milestone 3: implement basic functionality 10. Write a PHP script that allows users to vote on their favorite boy/girl baby name. Basically it should: o Display a form containing: a way to select boy or girl, a text input for typing in the name, and a Submit button. o Once the Submit button is pressed, record the users input into a table (separate from BABYNAMES), which you use to keep track of the votes received so far. o Display the most popular names so far (in decreasing order by number of votes). See https://www.ssa.gov/oact/babynames/ for an example of such table (limited to the top 10 baby names).

db_connect.php

// You will need to require this file on EVERY php file that uses the database. // Be sure to use $db->close(); at the end of each php file that includes this!

$dbhost = 'localhost'; // Most likely will not need to be changed $dbname = ''; $dbuser = ''; $dbpass = '';

$db = new mysqli($dbhost, $dbuser, $dbpass, $dbname);

if($db->connect_errno > 0) { die('Unable to connect to database [' . $db->connect_error . ']'); }

index.php

DB Table Test

Database Table Test

Step One Creating the table

query($createStmt)) { echo '
Table creation successful.
' . PHP_EOL; } else { echo '
Table creation failed: (' . $db->errno . ') ' . $db->error . '
' . PHP_EOL; exit(); // Prevents the rest of the file from running } ?>

Step Two Inserting into the table

query($insertStmt)) { echo '
Values inserted successfully.
' . PHP_EOL; } else { echo '
Value insertion failed: (' . $db->errno . ') ' . $db->error . '
' . PHP_EOL; exit(); } ?>

Step Three Retrieving the rows

query($selectStmt); if($result->num_rows > 0) { echo '
' . PHP_EOL; while($row = $result->fetch_assoc()) { echo '

id: ' . $row["id"] . ' - value: ' . $row["value"] . '

' . PHP_EOL; } echo '
' . PHP_EOL; } else { echo '
No Results
' . PHP_EOL; } ?>

Step Four Dropping the table

query($dropStmt)) { echo '
Table drop successful.
' . PHP_EOL; } else { echo '
Table drop failed: (' . $db->errno . ') ' . $db->error . '
' . PHP_EOL; exit(); } ?>

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!