Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

im making a vote naming website i just need someone to add pictures and a background to make the website more pleasant also if some

im making a vote naming website
i just need someone to add pictures
and a background to make the website more pleasant
also if some can add a chart that holds all the names and votes code is below:
//index.php
require_once 'db_connect.php';
?>
$file = fopen("names/yob2016.txt","r");
if ($result = $db->query("SELECT * from babynames")) {
/* determine number of rows result set */
$row_cnt = $result->num_rows;
/* close result set */
$result->close();
}
if ($row_cnt==0) { /* Table is empty */
while(! feof($file))
{
$line=fgets($file);
$var = explode(",", $line);
$name=(string)$var[0];
echo " ";
$sql = "INSERT INTO babynames(name, votes) VALUES ('$name', 0)";
if ($db->query($sql) === TRUE) {
} else {
echo "Error: " . $sql . " " . $db->error;
}
}
fclose($file);
}
?>
baby names
  • BabyName voting
    close();?>
    //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 = 'bn'; // Needs to be changed to your designated table database name
    $dbuser = 'root'; // Needs to be changed to reflect your LAMP server credentials
    $dbpass = ''; // 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 . ']');
    }
    //action_page.php
    require_once 'db_connect.php';
    if(isset($_GET['name']))
    {
    $n=$_GET['name'];
    $sqln = "select * from babynames where name='".$n."'";
    $result = $db->query($sqln);
    if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
    $name=$row['name'];$votes=$row['votes'];
    }
    }
    }
    $votes=$votes+1;
    $squ = "UPDATE babynames SET votes='".$votes."' WHERE name='".$name."'";
    if ($db->query($squ) === TRUE) {
    } else {
    echo "Error updating record: " . $conn->error;
    }
    $db->close();
    header("Location: index.php");
    ?>
    //the mysql database is bn
    //the table name is babynames, that contains columns bid(int),name(text),votes(int)

    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

    Gay, lesbian, bisexual, and transgender issues in sport

    Answered: 1 week ago