<html>
<head>
<title>Online Voting System</title>
<link rel="stylesheet" type="text/css" href="css/design.css">
<div class="aa">
</head>
<body>
<div class="main">
<div class="form_m">
<h2 style='color:white;'>Players Voting System</h2>
<form method="post" action="">
<input type="submit" name="shahid" value="AFRIDI">
<input type="submit" name="kohli" value="KOHLI">
<input type="submit" name="gayle" value="GAYLE">
</form>
</div>
</div>
</body>
</html>
<?php
include 'connection.php';
if(isset($_COOKIE['vote']))
{
echo "<h2 style='text-align:center;color:red;'>Can\'t vote again</h2>";
}
else{
//first portion
if(isset($_POST['shahid']))
{
setcookie('vote', true, time() + (10 * 365 * 24 * 60 * 60), "/");
$shahid=mysqli_query($con,"UPDATE players SET shahid=shahid+1");
if($shahid)
{
echo "<h3 style='margin-left:30px;'>You Are Cast Vote For Shahid Afridi.. </h3>";
$select_q=mysqli_query($con,"SELECT * FROM players");
while($run=mysqli_fetch_array($select_q))
{
$per_a=$run['shahid'];
$per_v=$run['kohli'];
$per_g=$run['gayle'];
$count=$per_a+$per_v+$per_g;
$per_player=round($per_a*100/$count).'%';
}
}
}
//second portion
if(isset($_POST['kohli']))
{
setcookie('vote', true, time() + (10 * 365 * 24 * 60 * 60), "/");
$kohli=mysqli_query($con,"UPDATE players SET kohli=kohli+1");
if($kohli)
{
echo "<h3 style='margin-left:30px;'>You Are Cast Vote For Virat Kohli..</h3>";
$select_q=mysqli_query($con,"SELECT * FROM players");
while($run=mysqli_fetch_array($select_q))
{
$per_a=$run['shahid'];
$per_v=$run['kohli'];
$per_g=$run['gayle'];
$count=$per_a+$per_v+$per_g;
$per_player=round($per_v*100/$count).'%';
}
}
}
//third portion
if(isset($_POST['gayle']))
{
setcookie('vote', true, time() + (10 * 365 * 24 * 60 * 60), "/");
$gayle=mysqli_query($con,"UPDATE players SET gayle=gayle+1");
if($gayle)
{
echo "<h3 style='margin-left:30px;'>You Are Cast Vote For Gayle..</h3>";
$select_q=mysqli_query($con,"SELECT * FROM players");
while($run=mysqli_fetch_array($select_q))
{
$per_a=$run['shahid'];
$per_v=$run['kohli'];
$per_g=$run['gayle'];
$count=$per_a+$per_g+$per_g;
$per_player=round($per_g*100/$count).'%';
}
}
}}
?>
<?php
include 'detail.php';
?>
</div>
Good luck
No comments:
Thanks for your feedback...