// Put this line in your index.php page... where you want the poll to appear
session_start(); if ( !session_is_registered("poll") ) {display_poll(); } else { display_poll_result(); }

// this function is dislayed only if the user didnt vote yet
<?PHP
function display_poll() {
$query "SELECT * FROM poll WHERE Poll_Flag = 1"// poll is the name of the table(in it can exist different polls) and if Poll_Flag = 1 that means that poll is in use...
$result=mysql_query($query);
while ( 
$r mysql_fetch_array($result) ){
$question $r['Poll_Question'];
$answer1 $r['Poll_Answer1'];
$answer2 $r['Poll_Answer2'];
$answer3 $r['Poll_Answer3'];

echo ("<form name=\"form1\" action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">");
echo(
"$question <br>");
echo(
"<input name=answer type=radio value=answer1> $answer1 <br>");
echo(
"<input name=answer type=radio value=answer2> $answer2 <br>");
echo(
"<input name=answer type=radio value=answer3> $answer3 <br>");
echo(
"<div align=\"right\"><input type=\"submit\" name=\"Vote\" value=\"Vote\"></div>");
echo (
"</form>");
}
}
//this function is displayed if the user have voted
function display_poll_result() {
$query "SELECT * FROM poll WHERE Poll_Flag = 1";
$result=mysql_query($query);
while ( 
$r mysql_fetch_array($result) ){
$question $r['Poll_Question'];
$answer1 $r['Poll_Answer1'];
$answer2 $r['Poll_Answer2'];
$answer3 $r['Poll_Answer3'];

$count1 $r['Poll_Table1'];
$count2 $r['Poll_Table2'];
$count3 $r['Poll_Table3'];

echo("$question <br><br>");
echo(
"- $answer1 $count1 %<br><table width=\"$count1%\"  border=\"0\" bgcolor=\"#000063\"><td></td></table> ");
echo(
"- $answer2 $count2 %<br><table width=\"$count2%\"  border=\"0\" bgcolor=\"#FF0000\"><td></td></table>");
echo(
"- $answer3 $count3 %<br><table width=\"$count3%\"  border=\"0\" bgcolor=\"#009900\"><td></td></table>");
echo(
"<br><div align=\"center\">You already voted !</div>");
}
}
?>
<?PHP
$Vote 
$_POST['Vote'];
if(isset(
$Vote) ){

session_start();
if ( 
session_is_registered("poll")) {

}
else{
session_register("poll");

$answer $_POST['answer'];
$query "SELECT * FROM poll WHERE Poll_Flag = 1";
$result=mysql_query($query);
while ( 
$r mysql_fetch_array($result) )
{
$id $r['Poll_Id'];
$count1 $r['Poll_Answer1Count'];
$count2 $r['Poll_Answer2Count'];
$count3 $r['Poll_Answer3Count'];
}
if( 
$answer == "answer1" ){
$count1++;
$total $count1 $count2 $count3;
$table1 = ( $count1 100 ) / $total;
$table2 = ( $count2 100 ) / $total;
$table3 = ( $count3 100 ) / $total;
$updatequery =  "UPDATE poll SET Poll_Answer1Count = '$count1' WHERE Poll_Flag = 1";
mysql_query$updatequery );
}
if( 
$answer == "answer2" ){
$count2++;
$total $count1 $count2 $count3;
$table1 = ( $count1 100 ) / $total;
$table2 = ( $count2 100 ) / $total;
$table3 = ( $count3 100 ) / $total;
$updatequery =  "UPDATE poll SET Poll_Answer2Count = '$count2' WHERE Poll_Flag = 1";
mysql_query$updatequery );
}
if( 
$answer == "answer3" ){
$count3++;
$total $count1 $count2 $count3;
$table1 = ( $count1 100 ) / $total;
$table2 = ( $count2 100 ) / $total;
$table3 = ( $count3 100 ) / $total;
$updatequery =  "UPDATE poll SET Poll_Answer3Count = '$count3' WHERE Poll_Flag = 1";
mysql_query$updatequery );
}
$updatequery =  "UPDATE poll SET Poll_Table1 = '$table1' WHERE Poll_Flag = 1";
mysql_query$updatequery );
$updatequery =  "UPDATE poll SET Poll_Table2 = '$table2' WHERE Poll_Flag = 1";
mysql_query$updatequery );
$updatequery =  "UPDATE poll SET Poll_Table3 = '$table3' WHERE Poll_Flag = 1";
mysql_query$updatequery );

$_SESSION['poll'] = $id ;
}
}
?>

// ADMINISTRATOR INTERFACE //
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?php
session_start
();
if (!
session_is_registered("statusCheck"))
die(
"<strong>Your session has timed out ! Log In again </strong>");
?>
<?PHP
$query 
"SELECT * FROM poll WHERE Poll_Flag = 0";
$result=mysql_query($query);
$i=0;
$names="";
while ( 
$r mysql_fetch_array($result) ){
$question[$i] = $r['Poll_Question'];
$names .= "<option>".$question[$i]."</option>";
$i++;
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css">
<!--
.Nahda {
font-family: Tahoma;
font-size: small;
font-style: normal;
text-decoration: none;
color: #000063;
font-weight: bold;
}
.NahdaSmall {
font-family: Tahoma;
font-size: xx-small;
font-style: normal;
color: #000063;
font-weight: 300;
}
a:link {
text-decoration: none;
color: #000063;
}
a:visited {
text-decoration: none;
color: #000063;
}
a:hover {
text-decoration: underline;
color: #0000CC;
}
a:active {
text-decoration: none;
color: #0000663;
}
.style28 {font-style: italic; color: #660000;}
-->
</style>
</head>

<body>
<form name="form1" action="../tmp/confirmation.php" method="post">
<table width="100%"  border="0">
<tr>
<td class="Nahda">Select Existing Polls:<font color="#000000" size="3" face="Arial, Helvetica, sans-serif"><strong></strong></font> <span class="style28" onClick="open_help()" style="cursor:help"><font face="Arial, Helvetica, sans-serif"><u>help</u></font> </span></td>
</tr>
<tr>
<td align="left" valign="top" class="Nahda"><select name="select" size="5">
<?PHP echo("$names");?>
    </select>
<br>
<em>P.S.: if only one letter appear try refreshing the page ! </em></td>
</tr>
<tr>
<td class="Nahda"><div align="right">
<input type="submit" name="Submit" value="Submit">
</div></td>
</tr>
</table>
<br>
<hr>
</form>
<form name="form2" action="../tmp/confirmation.php" method="post">
<table width="100%"  border="0">
<tr>
<td colspan="2" class="Nahda">Or Create a new one: <font color="#000000" size="3" face="Arial, Helvetica, sans-serif"><strong></strong></font> <span class="style28" onClick="open_help()" style="cursor:help"><font face="Arial, Helvetica, sans-serif"><u>help</u></font> </span><font color="#000000" size="3" face="Arial, Helvetica, sans-serif"><strong></strong></font></td>
</tr>
<tr>
<td width="50%" align="left" valign="top" class="Nahda"><p>Question:<br>
<input name="question" type="text" id="question" size="30">
</p>
<p>Answer1:<br>
<input name="answer1" type="text" id="answer1" size="30">
</p>
</td>
<td align="left" valign="top" class="Nahda"><p>Answer2:<br>
<input name="answer2" type="text" id="answer2" size="30">
</p>
<p>Answer3:<br>
<input name="answer3" type="text" id="answer3" size="30">
</p></td>
</tr>
<tr>
<td colspan="2" class="Nahda"><div align="right">
<input name="Create" type="submit" id="Create" value="Create">
</div></td>
</tr>
</table>
</form>
<hr>
<p>&nbsp;</p>
</body>
</html>