Creating a Dynamic Poll Website using PHP, MySQL, HTML, and CSS
VerifiedAdded on 2019/09/21
|18
|3297
|356
Practical Assignment
AI Summary
This assignment presents the code for a complete poll website developed using PHP and MySQL. The website includes several key functionalities: a home page, a login/signup system, a page for creating polls, a page to view and answer the polls, and a results page. The home page features a logo, introductory text, and links to create polls and log in/sign up. The login/signup page allows users to create accounts and log in to access the poll creation functionality. The polling page enables authenticated users to create new poll questions along with answer options. The question page displays a list of available polls, and the answer page allows users to vote on a selected poll. Finally, the results page displays the results of the polls in a bar graph format, along with the total number of polls for each question. The code is designed to demonstrate the basic functionalities of a poll website, including user authentication, database interaction, and dynamic content display. The assignment provides a practical example of web development using PHP and MySQL, showcasing how to build interactive web applications.

Home Page - Index.php
<?php
include_once('connect.php'); //include connection file
?>
<!DOCTYPE html>
<html>
<body>
<img src="logo.png " alt="logo" style="width:150px;height:150px;">
<head>
<link rel="stylesheet" type="text/css" href="css/style.css">
<meta charset="UTF-8">
<title>Poll voting</title>
<div class="h1">
<h1>Poll Here and Look at People Thoughts</h1>
</div>
<div class="h2">
<h2>Free Poll/Voting System that Is Available for Anyone</h2>
</div>
<!-- adding a clicable button for new page for voting-->
<a href="polling.php" class="button"> Create Your Polls Here</a>
</head>
<header>
<div class="header">
<nav class="navigation">
<?php
include_once('connect.php'); //include connection file
?>
<!DOCTYPE html>
<html>
<body>
<img src="logo.png " alt="logo" style="width:150px;height:150px;">
<head>
<link rel="stylesheet" type="text/css" href="css/style.css">
<meta charset="UTF-8">
<title>Poll voting</title>
<div class="h1">
<h1>Poll Here and Look at People Thoughts</h1>
</div>
<div class="h2">
<h2>Free Poll/Voting System that Is Available for Anyone</h2>
</div>
<!-- adding a clicable button for new page for voting-->
<a href="polling.php" class="button"> Create Your Polls Here</a>
</head>
<header>
<div class="header">
<nav class="navigation">
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

<div class="sign-up">
<?php if(isset($_SESSION['login'])) { ?>
<a href="logout.php">log out</a>
<?php } else { ?>
<a href="login.php">log in</a>
<a href="login.php">sign up</a>
<?php } ?>
</div>
<div class="navbar">
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Help</a>
<a href="#">Contact</a>
</div>
</nav>
<div class="video-container">
<video autoplay loop muted id="video-bg">
<source src="bg.mp4" type="video/mp4">
</video>
</div>
</div>
</body>
</header>
</html>
<?php if(isset($_SESSION['login'])) { ?>
<a href="logout.php">log out</a>
<?php } else { ?>
<a href="login.php">log in</a>
<a href="login.php">sign up</a>
<?php } ?>
</div>
<div class="navbar">
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Help</a>
<a href="#">Contact</a>
</div>
</nav>
<div class="video-container">
<video autoplay loop muted id="video-bg">
<source src="bg.mp4" type="video/mp4">
</video>
</div>
</div>
</body>
</header>
</html>

Login/SignUp Page - login.php
<?php
include_once('connect.php'); //include connection file
if(isset($_POST['login'])) { //if user login
$uname = $_POST['username']; //get username from the form
$password = $_POST['password']; //get password from the form
$qryChkData = mysql_query("select * from users where username='".$uname."' and
user_password='".$password."'"); // query for check login //check for login
$rowNum = mysql_num_rows($qryChkData);
if($rowNum > 0) {
$_SESSION['login'] = "Success";
header('location:polling.php'); //go to polling page
}
else {
$_SESSION['msg'] = "E-Mail or Password Is not Correct"; //message for incorrect e-
mail or password
}
}
if(isset($_POST['signUp'])) { //if user click on signup
$uname = $_POST['username']; //get username
$email =$_POST['email']; //get email
$password = $_POST['password']; //get password
$qryInsertData = mysql_query("insert into users (username, user_email, user_password)
values ('".$uname."', '".$email."', '".$password."')"); // query to signup
<?php
include_once('connect.php'); //include connection file
if(isset($_POST['login'])) { //if user login
$uname = $_POST['username']; //get username from the form
$password = $_POST['password']; //get password from the form
$qryChkData = mysql_query("select * from users where username='".$uname."' and
user_password='".$password."'"); // query for check login //check for login
$rowNum = mysql_num_rows($qryChkData);
if($rowNum > 0) {
$_SESSION['login'] = "Success";
header('location:polling.php'); //go to polling page
}
else {
$_SESSION['msg'] = "E-Mail or Password Is not Correct"; //message for incorrect e-
mail or password
}
}
if(isset($_POST['signUp'])) { //if user click on signup
$uname = $_POST['username']; //get username
$email =$_POST['email']; //get email
$password = $_POST['password']; //get password
$qryInsertData = mysql_query("insert into users (username, user_email, user_password)
values ('".$uname."', '".$email."', '".$password."')"); // query to signup
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

if($qryInsertData) {
$_SESSION['login'] = "Success";
header('location:polling.php');
}
else {
$_SESSION['msg'] = "Error In Sign Up"; //error message for invalid login
details
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Poll voting</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
$_SESSION['login'] = "Success";
header('location:polling.php');
}
else {
$_SESSION['msg'] = "Error In Sign Up"; //error message for invalid login
details
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Poll voting</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

<body>
<header class="header-basic">
<div class="header-limiter">
<h1 style="margin-left:180px;"><a href="#">Poll Here and
Look at People Thoughts</a></h1>
<nav>
<a href="index.php">Home</a>
<a href="polling.php">Polls</a>
<?php if(isset($_SESSION['login'])) { ?>
<a href="logout.php">Logout</a>
<?php } else { ?>
<a href="login.php">Log In</a>
<?php } ?>
</nav>
</div>
</header>
<header class="header-basic">
<div class="header-limiter">
<h1 style="margin-left:180px;"><a href="#">Poll Here and
Look at People Thoughts</a></h1>
<nav>
<a href="index.php">Home</a>
<a href="polling.php">Polls</a>
<?php if(isset($_SESSION['login'])) { ?>
<a href="logout.php">Logout</a>
<?php } else { ?>
<a href="login.php">Log In</a>
<?php } ?>
</nav>
</div>
</header>

<div style="width:60%; margin-left:200px; background-color:#3f3f6f; text-align:
center;">
<form action="" method="post">
<?php if(isset($_SESSION['msg'])) { ?><h1 style="color:white;"><?php echo
$_SESSION['msg']; unset($_SESSION['msg']); }?></h1>
<h1 style="color:white;"> Login Here:</h1>
<input type="text" name="username" placeholder="*Username" required><br><br>
<input type="password" name="password" placeholder="*Password"
required><br><br>
<input type="submit" name="login" value="Login" class="button"
style="width:8%;">
</form>
<form action="" method="post">
<h1 style="color:white;"> Sign Up Here:</h1>
<input type="text" name="username" placeholder="*Username" required><br><br>
<input type="text" name="email" placeholder="*E-Mail" required><br><br>
<input type="password" name="password" placeholder="*Password"
required><br><br>
<input type="submit" name="signUp" value="Sign Up" class="button"
style="width:9%;">
</form>
</div>
</body>
</html>
center;">
<form action="" method="post">
<?php if(isset($_SESSION['msg'])) { ?><h1 style="color:white;"><?php echo
$_SESSION['msg']; unset($_SESSION['msg']); }?></h1>
<h1 style="color:white;"> Login Here:</h1>
<input type="text" name="username" placeholder="*Username" required><br><br>
<input type="password" name="password" placeholder="*Password"
required><br><br>
<input type="submit" name="login" value="Login" class="button"
style="width:8%;">
</form>
<form action="" method="post">
<h1 style="color:white;"> Sign Up Here:</h1>
<input type="text" name="username" placeholder="*Username" required><br><br>
<input type="text" name="email" placeholder="*E-Mail" required><br><br>
<input type="password" name="password" placeholder="*Password"
required><br><br>
<input type="submit" name="signUp" value="Sign Up" class="button"
style="width:9%;">
</form>
</div>
</body>
</html>
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

Polls Page - polling.php
<?php
include_once('connect.php'); //include connection file
if(!isset($_SESSION['login'])) {
header('location:login.php');
}
if(isset($_POST['submit'])) {
$ques = $_POST['question'];
$ans1 =$_POST['ans1'];
$ans2 =$_POST['ans2'];
$ans3 =$_POST['ans3'];
$ans4 =$_POST['ans4'];
$qryInsertData = mysql_query("insert into questions (question, ans1, ans2, ans3, ans4) values
('".$ques."', '".$ans1."', '".$ans2."', '".$ans3."', '".$ans4."')"); //query to add question and
answers
header('location:questions.php'); // move to question page
}
?>
<!DOCTYPE html>
<html>
<head>
<?php
include_once('connect.php'); //include connection file
if(!isset($_SESSION['login'])) {
header('location:login.php');
}
if(isset($_POST['submit'])) {
$ques = $_POST['question'];
$ans1 =$_POST['ans1'];
$ans2 =$_POST['ans2'];
$ans3 =$_POST['ans3'];
$ans4 =$_POST['ans4'];
$qryInsertData = mysql_query("insert into questions (question, ans1, ans2, ans3, ans4) values
('".$ques."', '".$ans1."', '".$ans2."', '".$ans3."', '".$ans4."')"); //query to add question and
answers
header('location:questions.php'); // move to question page
}
?>
<!DOCTYPE html>
<html>
<head>
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

<title>Poll voting</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<header class="header-basic">
<div class="header-limiter">
<h1 style="margin-left:180px;"><a href="#">Poll Here and
Look at People Thoughts</a></h1>
<nav>
<a href="index.php">Home</a>
<a href="polling.php">Polls</a>
<a href="logout.php">Logout</a>
</nav>
</div>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<header class="header-basic">
<div class="header-limiter">
<h1 style="margin-left:180px;"><a href="#">Poll Here and
Look at People Thoughts</a></h1>
<nav>
<a href="index.php">Home</a>
<a href="polling.php">Polls</a>
<a href="logout.php">Logout</a>
</nav>
</div>

</header>
<div style="width:60%; margin-left:200px; background-color:#3f3f6f; text-align:
center;">
<form action="" method="post">
<h1 style="color:white;"> Poll Question:</h1>
<textarea name="question" placeholder="Question?"></textarea>
<h1 style="color:white;"> Option Answers:</h1>
<input type="text" name="ans1" placeholder="*Option 1" required><br><br>
<input type="text" name="ans2" placeholder="*Option 2" required><br><br>
<input type="text" name="ans3" placeholder="*Option 3" required><br><br>
<input type="text" name="ans4" placeholder="*Option 4" required><br><br>
<input type="submit" name="submit" value="Submit" class="button" style="width:8%;">
</form>
</div>
</body>
</html>
<div style="width:60%; margin-left:200px; background-color:#3f3f6f; text-align:
center;">
<form action="" method="post">
<h1 style="color:white;"> Poll Question:</h1>
<textarea name="question" placeholder="Question?"></textarea>
<h1 style="color:white;"> Option Answers:</h1>
<input type="text" name="ans1" placeholder="*Option 1" required><br><br>
<input type="text" name="ans2" placeholder="*Option 2" required><br><br>
<input type="text" name="ans3" placeholder="*Option 3" required><br><br>
<input type="text" name="ans4" placeholder="*Option 4" required><br><br>
<input type="submit" name="submit" value="Submit" class="button" style="width:8%;">
</form>
</div>
</body>
</html>
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

Question Page - question.php
<?php
include_once('connect.php');
$qryquestion = mysql_query("select * from questions"); // query to get all list of questions
?>
<!DOCTYPE html>
<html>
<head>
<title>Poll voting</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<header class="header-basic">
<?php
include_once('connect.php');
$qryquestion = mysql_query("select * from questions"); // query to get all list of questions
?>
<!DOCTYPE html>
<html>
<head>
<title>Poll voting</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<header class="header-basic">
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

<div class="header-limiter">
<h1 style="margin-left:180px;"><a href="#">Poll Here and
Look at People Thoughts</a></h1>
<nav>
<a href="index.php">Home</a>
<a href="polling.php">Polls</a>
<a href="logout.php">Logout</a>
</nav>
</div>
</header>
<div style="width:60%; margin-left:200px; background-color:#3f3f6f; text-align:
center;">
<h1 style="color:white;">Choose Any Question Below: </h1>
<?php while($sqlData = mysql_fetch_assoc($qryquestion)) { ?>
<h2><a href="answers.php?qid=<?php echo $sqlData['questions_id']; ?>" style="color:
#9a700a; text-decoration: none;">Q. <?php echo $sqlData['question']; ?>?</a></h2>
<?php } ?>
</div>
</body>
</html>
<h1 style="margin-left:180px;"><a href="#">Poll Here and
Look at People Thoughts</a></h1>
<nav>
<a href="index.php">Home</a>
<a href="polling.php">Polls</a>
<a href="logout.php">Logout</a>
</nav>
</div>
</header>
<div style="width:60%; margin-left:200px; background-color:#3f3f6f; text-align:
center;">
<h1 style="color:white;">Choose Any Question Below: </h1>
<?php while($sqlData = mysql_fetch_assoc($qryquestion)) { ?>
<h2><a href="answers.php?qid=<?php echo $sqlData['questions_id']; ?>" style="color:
#9a700a; text-decoration: none;">Q. <?php echo $sqlData['question']; ?>?</a></h2>
<?php } ?>
</div>
</body>
</html>

Answer Page – answer.php
<?php
include_once('connect.php'); //include connection file
$ques_id = $_GET['qid']; //get question id
$qryAnswer = mysql_query("select * from questions where questions_id='".$ques_id."'"); //
query to get questions
$arrData = mysql_fetch_assoc($qryAnswer);
if(isset($_POST['submit'])) {
$ans = $_POST['ans'];
$qryInsertData = mysql_query("insert into polls (question_id, answer_id) values ('".
$ques_id."', '".$ans."')"); //query to insert data
header("Location:results.php?qid=".$ques_id);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Poll voting</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<?php
include_once('connect.php'); //include connection file
$ques_id = $_GET['qid']; //get question id
$qryAnswer = mysql_query("select * from questions where questions_id='".$ques_id."'"); //
query to get questions
$arrData = mysql_fetch_assoc($qryAnswer);
if(isset($_POST['submit'])) {
$ans = $_POST['ans'];
$qryInsertData = mysql_query("insert into polls (question_id, answer_id) values ('".
$ques_id."', '".$ans."')"); //query to insert data
header("Location:results.php?qid=".$ques_id);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Poll voting</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide
1 out of 18
Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
Copyright © 2020–2025 A2Z Services. All Rights Reserved. Developed and managed by ZUCOL.