Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions