Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I really need help on milestone 3 & 4. I\'ve got 1 & 2. Just need to implent the

ID: 3911284 • Letter: I

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

<?php require_once('db_connect.php'); ?>

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="utf-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>Baby Names</title>

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">

</head>

<body>

<div class="container">

<div class="page-header">

<h1>Baby Names</h1>

</div>

<?php

// 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 ' <div class="alert alert-success">Table creation successful.</div>' . PHP_EOL;

} else {

echo ' <div class="alert alert-danger">Table creation failed: (' . $db->errno . ') ' . $db->error . '</div>' . 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){

?>

<table class="table table-responsive">

<thead>

<tr>

<th>Name</th>

<th>Gender</th>

<th>Occurences</th>

</thead>

<tbody>

<?php

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

?>

<tr>

<td><?php echo $row['name']; ?></td>

<td><?php echo $row['gender']; ?></td>

<td><?php echo $row['occurences']; ?></td>

</tr>

<?php

}

}

?>

</tbody>

</table>

<?php

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

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

?>

<?php

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

echo ' <div class="alert alert-success">Table drop successful.</div>' . PHP_EOL;

} else {

echo ' <div class="alert alert-danger">Table drop failed: (' . $db->errno . ') ' . $db->error . '</div>' . PHP_EOL;

exit();

}

?>

</div>

</body>

</html>

--------------------------------------db_connect.php----------------------------------------------------------------------------------

<?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 = '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.

Explanation / Answer

Create new database-

<?php

echo "creating database ";

try {

   $dbh = new PDO('sqlite:voting.db');

   $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

   $dbh->exec('

       CREATE TABLE tally (

       QID varchar(32) NOT NULL,

       AID integer NOT NULL,

       votes integer NOT NULL,

       PRIMARY KEY (QID,AID))

   ');

}

catch(PDOException $e) {

   echo "ERROR!!: $e";

   exit;

}

echo "db created successfully.";

?>

Then design view of the poll-

<form class="webPoll" method="post" action="test.php">

   <h4>What question would you like to ask?</h4>

   <ul>

       <li>Answer Here</li>

       <li>Another Answer Here</li>

   </ul>

</form>

<

form class="webPoll" method="post" action="test.php">

   <h4>What question would you like to ask?</h4>

   <ul>

       <li>

           <label class='poll_active'>

           <input type='radio' name='AID' value='0'>

           First Answer Here

           </label>

       </li>

   </ul>

</form>

Add fieldset tag to open up some styling options, and of course we need a submit button!

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

<form class="webPoll" method="post" action="/poll/test.php">

   <h4>What question would you like to ask?</h4>

   <fieldset>

   <ul>

       <li>

           <label class='poll_active'>

           <input type='radio' name='AID' value='0'>

           First Answer Here

           </label>

       </li>

   </ul>

   </fieldset>

   <p class="buttons">

       <button type="submit" class="vote">Vote!</button>

   </p>

</form>

Include one answer view-

<li>

   <div class='result'>&nbsp;</div>

   <label class='poll_results'>

       10%: First Answer Here

   </label>

</li>

Then Style the Form Tag

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

form.webPoll {

   background:#ededed;

   behavior:url(PIE.php);

   border:1px solid #bebebe;

   -moz-border-radius:8px;

   -webkit-border-radius:8px;

   border-radius:8px;

   -moz-box-shadow:#666 0 2px 3px;

   -webkit-box-shadow:#666 0 2px 3px;

   box-shadow:#666 0 2px 3px;

   margin:10px 0 10px 8px;

   padding:6px;

   position:relative;

   width:246px;

}

<?php

echo "creating database ";

try {

   $dbh = new PDO('sqlite:voting.db');

   $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

   $dbh->exec('

       CREATE TABLE tally (

       QID varchar(32) NOT NULL,

       AID integer NOT NULL,

       votes integer NOT NULL,

       PRIMARY KEY (QID,AID))

   ');

}

catch(PDOException $e) {

   echo "ERROR!!: $e";

   exit;

}

echo "db created successfully.";

?>