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

Milestone 4: implement enhanced functionality 11. Once the app is fully functional, add AJAX capabilities to it, namely: implement a method to autosuggest / autocomplete popular baby names based on the keystrokes typed by the user so far.

db_connect.php

// Do not change the following two lines. $teamURL = dirname($_SERVER['PHP_SELF']) . DIRECTORY_SEPARATOR; $server_root = dirname($_SERVER['PHP_SELF']);

// 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

require_once './php/db_connect.php'; ?>

DB Table Test

Database Table Test

// Create table with two columns: id and value $createStmt = 'CREATE TABLE `TEST` (' . PHP_EOL . ' `id` int(11) NOT NULL AUTO_INCREMENT,' . PHP_EOL . ' `value` varchar(50) DEFAULT NULL,' . PHP_EOL . ' PRIMARY KEY (`id`)' . PHP_EOL . ') ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;'; ?>

Step One Creating the table

if($db->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 } ?>

// Add two rows to the table $insertStmt = 'INSERT INTO `TEST` (`id`, `value`)' . PHP_EOL . ' VALUES (NULL, \'Test 1\'),' . PHP_EOL . ' (NULL, \'Lorem Ipsum\');'; ?>

Step Two Inserting into the table

if($db->query($insertStmt)) { echo '

Values inserted successfully.

' . PHP_EOL; } else { echo '

Value insertion failed: (' . $db->errno . ') ' . $db->error . '

' . PHP_EOL; exit(); } ?>

// Get the rows from the table $selectStmt = 'SELECT * FROM `TEST`;'; ?>

Step Three Retrieving the rows

$result = $db->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; } ?>

// Drop the TEST table now that we're done with it $dropStmt = 'DROP TABLE `TEST`;'; ?>

Step Four Dropping the table

if($db->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!