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

i’m making a vote naming website i just need someone to add pictures and a backg

ID: 3911241 • Letter: I

Question

i’m 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
<?php
require_once 'db_connect.php';
?>
<?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 "<br>";
$sql = "INSERT INTO babynames(name, votes) VALUES ('$name', 0)";
if ($db->query($sql) === TRUE) {
} else {
echo "Error: " . $sql . "<br>" . $db->error;
}
}
fclose($file);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>baby names</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<style>
.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%);
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-custom ">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="#">BabyName voting</a>
</li>
</ul>
</nav>
<div class="container-fluid">
<div class="col-sm-6 container centered">
<input class='name'/>
<button type="submit" class="button btn btn-primary">submit</button
<script>
<div class="form">
<?php
$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 '
<label for="nme">Name: '.$name.', </label>
<label for="voteno.">Votes: '.$votes.' </label>
<br />
<br />
';
}
}
?>
<script>
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
}
</script>
</div>
</div>
</div>
</div>
</body>
</html>
<? $db->close();?>
//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 = '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
<?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) i’m 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
<?php
require_once 'db_connect.php';
?>
<?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 "<br>";
$sql = "INSERT INTO babynames(name, votes) VALUES ('$name', 0)";
if ($db->query($sql) === TRUE) {
} else {
echo "Error: " . $sql . "<br>" . $db->error;
}
}
fclose($file);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>baby names</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<style>
.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%);
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-custom ">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="#">BabyName voting</a>
</li>
</ul>
</nav>
<div class="container-fluid">
<div class="col-sm-6 container centered">
<input class='name'/>
<button type="submit" class="button btn btn-primary">submit</button
<script>
<div class="form">
<?php
$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 '
<label for="nme">Name: '.$name.', </label>
<label for="voteno.">Votes: '.$votes.' </label>
<br />
<br />
';
}
}
?>
<script>
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
}
</script>
</div>
</div>
</div>
</div>
</body>
</html>
<? $db->close();?>
//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 = '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
<?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) 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
<?php
require_once 'db_connect.php';
?>
<?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 "<br>";
$sql = "INSERT INTO babynames(name, votes) VALUES ('$name', 0)";
if ($db->query($sql) === TRUE) {
} else {
echo "Error: " . $sql . "<br>" . $db->error;
}
}
fclose($file);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>baby names</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<style>
.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%);
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-custom ">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="#">BabyName voting</a>
</li>
</ul>
</nav>
<div class="container-fluid">
<div class="col-sm-6 container centered">
<input class='name'/>
<button type="submit" class="button btn btn-primary">submit</button
<script>
<div class="form">
<?php
$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 '
<label for="nme">Name: '.$name.', </label>
<label for="voteno.">Votes: '.$votes.' </label>
<br />
<br />
';
}
}
?>
<script>
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
}
</script>
</div>
</div>
</div>
</div>
</body>
</html>
<? $db->close();?>
//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 = '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
<?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) //index.php
<?php
require_once 'db_connect.php';
?>
<?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 "<br>";
$sql = "INSERT INTO babynames(name, votes) VALUES ('$name', 0)";
if ($db->query($sql) === TRUE) {
} else {
echo "Error: " . $sql . "<br>" . $db->error;
}
}
fclose($file);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>baby names</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<style>
.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%);
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-custom ">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="#">BabyName voting</a>
</li>
</ul>
</nav>
<div class="container-fluid">
<div class="col-sm-6 container centered">
<input class='name'/>
<button type="submit" class="button btn btn-primary">submit</button
<script>
<div class="form">
<?php
$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 '
<label for="nme">Name: '.$name.', </label>
<label for="voteno.">Votes: '.$votes.' </label>
<br />
<br />
';
}
}
?>
<script>
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
}
</script>
</div>
</div>
</div>
</div>
</body>
</html>
<? $db->close();?>
//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 = '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
<?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)

Explanation / Answer

<?php

require_once 'db_connect.php';

?>

<?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 "<br>";

$sql = "INSERT INTO babynames(name, votes) VALUES ('$name', 0)";

if ($db->query($sql) === TRUE) {

} else {

echo "Error: " . $sql . "<br>" . $db->error;

}

}

fclose($file);

}

?>

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8" />

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

<title>baby names</title>

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

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

<style>

body{

background: linear-gradient(110deg, #fdcd3b 60%, #ffed4b 60%);

}

.navbar-custom{

background-color:blue;

}

.nav-link{

color: white;

text-align: right;

}

.nav-link:hover{

color:white;

}

.centered {

position: absolute;

top: 10%;

left: 50%;

transform: translate(-50%, 0%);

}

table{

background-color:#fff !important;

}

</style>

</head>

<body>

<nav class="navbar navbar-expand-sm navbar-custom ">

<ul class="navbar-nav ml-auto">

<li class="nav-item">

<a class="nav-link" href="#">BabyName voting</a>

</li>

</ul>

</nav>

<div class="container-fluid">

<div class="col-sm-6 container centered">

<div class="form-row align-items-center">

<div class="col-auto">

<input type="text" class="name form-control" placeholder="Enter baby name...">

</div>

<div class="col-auto">

<button type="submit" class="btn btn-primary mb-2">submit</button>

</div>

</div>

<?php

$sqln = "select * from babynames";

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

if ($result->num_rows > 0) {

// Output table header

echo '<table class="table">

<thead>

<tr>

<th scope="col">#</th>

<th scope="col">Baby Name</th>

<th scope="col">Votes</th>

</tr>

</thead>

<tbody>';

// output data of each row

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

$bid=$row['bid'];

$name=$row['name'];

$votes=$row['votes'];

echo '

<tr>

<td>'.$bid.'</td>

<td>'.$name.'</td>

<td>'.$votes.'</td>

</tr>';

}

echo '</tbody></table>';

}

?>

<script>

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

}

</script>

</div>

</div>

</div>

</div>

</body>

</html>

<? $db->close();?>

//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 = '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 . ']');

}