Answered step by step
Verified Expert Solution
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 baby names
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);
}
?>
.navbar-custom{
background-color:blue;
}
.nav-link{
color: white;
text-align: right;
}
.nav-link:hover{
color:white;
}
.centered {
position: absolute;
top: 20%;
left: 50%;
transform: translate(-50%, 0%);
}
BabyName voting
$sqln = "select * from babynames";
$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'];
echo '
';
}
}
?>
function vote()
{
var name=document.getElementsByClassName('name');
name=name[0].value; //passing name input value
window.location = '/babynames/action_page.php?name='+name; //giving param to action_page.php
}
$db->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
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