Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I really need help on milestone 3 & 4. I've got 1 & 2. Just need to implent the user's name choice and such. Design

I really need help on milestone 3 & 4. I've got 1 & 2.

Just need to implent the user's name choice and such.

Design an app / site that allow users to vote on their favorite baby names and displays updated statistics of the most popular baby names. It should demonstrate your knowledge of (primarily) PHP, and MySQL and build upon your existing knowledge of HTML, CSS, Bootstrap, JavaScript, and jQuery.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

--------------------------This is my tabletest so far---------------------

Baby Names

Baby Names

// Create table with four columns: id, name, gender and no of occurences of the name

$createStmt = 'CREATE TABLE IF NOT EXISTS `babynames` (' . PHP_EOL

//. ' `id` int(11) NOT NULL AUTO_INCREMENT,' . PHP_EOL

. ' `name` varchar(15) DEFAULT NULL,' . PHP_EOL

. ' `gender` char(1) DEFAULT NULL,' . PHP_EOL

. ' `occurences` int(10)' . PHP_EOL

//. ' PRIMARY KEY (`id`)' . PHP_EOL

. ') ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;';

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

}

// Read data from File and insert into database

$file = fopen("yob2016.txt", "r");

if($file){

while (!feof($file)) {

$data = explode(",", fgets($file));

$insert_stmt = 'INSERT INTO `babynames` (`name`, `gender`, `occurences`)'.PHP_EOL

.'VALUES (\''.$data[0].'\', \''.$data[1].'\', '.(int)$data[2].');';

if(!$db->query($insert_stmt)){

die('Error while inserting data to database');

}

}

}

fclose($file);

// Read the data names from Table and display on webpage

$select_statement = 'SELECT * FROM `babynames;';

$result = $db->query($select_statement);

if($result->num_rows>0){

?>

while($row=$result->fetch_assoc()){

?>

}

}

?>

Name Gender Occurences

// Drop the TEST table now that we're done with it

$dropStmt = 'DROP TABLE `babynames`;';

?>

if($db->query($dropStmt)) {

echo '

Table drop successful.
' . PHP_EOL;

} else {

echo '

Table drop failed: (' . $db->errno . ') ' . $db->error . '
' . PHP_EOL;

exit();

}

?>

--------------------------------------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 = 'FAU Username'; // Needs to be changed to your designated table database name $dbuser = 'FAU Username'; // Needs to be changed to reflect your LAMP server credentials $dbpass = 'DB Password'; // Needs to be changed to reflect your LAMP server credentials

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

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

Milestone 1: connection with database (starter code: 'tableTest') 2. Download the tableTest.zip file from Blackboard. It consists of two files: tabletest.php and Update your db_connect.php file with your proper credentials. Upload the two files (maintaining the proper directory structure) to your area on the server. Run tabletest.php to test if you can successfully connect to the database. It should show the following: 3. 4. 5

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

Step: 3

blur-text-image

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

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

More Books

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago