Question
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.
--------------------------This is my tabletest so far---------------------
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 '
} else {
echo '
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){
?>
Name | Gender | Occurences |
---|---|---|
// Drop the TEST table now that we're done with it
$dropStmt = 'DROP TABLE `babynames`;';
?>
if($db->query($dropStmt)) {
echo '
} else {
echo '
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started