De tabellen voor de database:

DROP TABLE IF EXISTS poll_answers;
CREATE TABLE poll_answers (
id tinyint(5) NOT NULL auto_increment,
poll_id tinyint(5) default '0',
answer varchar(100) default NULL,
votes int(4) default '0',
PRIMARY KEY  (id)
) TYPE=MyISAM;

DROP TABLE IF EXISTS poll_questions;
CREATE TABLE poll_questions (
id tinyint(5) NOT NULL auto_increment,
question varchar(100) default NULL,
total_votes int(4) default '0',
PRIMARY KEY  (id)
) TYPE=MyISAM;

===========================================

poll.php
<?php
function showpoll()
{
  // This function is to show the question, or the answer
  
  // Cookie
  $cookie = $_COOKIE['poll'];
  
  // Check if cookie exsists
  if (empty($cookie))
  {
    // Show the last question (function)
    showlast();
  } else {
    // Check if cookie is still valid (function)
    cookiecheck($cookie);
  }
}

function showlast()
{
  // This function shows the last question and its answers
  
  // Collect the question from the DB
  $query = mysql_query("SELECT id, question FROM poll_questions ORDER BY id DESC LIMIT 0,1");
  $num = mysql_num_rows($query);
  
  if (empty($num))
  {
    echo "Error: Didn't find questions!";
  } else {
    $question = mysql_fetch_row($query);
    
    // Start of the form
    echo "<form name=\"poll\" action=\"pollvote.php?redirect=".$_SERVER['REQUEST_URI']."\" method=\"post\">\n";
    
    // Show the question
    echo $question[1]."<br>\n";

    // Collect the answers from the DB
    $query = mysql_query("SELECT id, answer FROM poll_answers WHERE poll_id = '$question[0]' ORDER BY id");
    $num = mysql_num_rows($query);
    if (empty($num))
    {
    	echo "Error: Didn't find any answers!";
    } else {
      while ($answer = mysql_fetch_row($query))
      {
        // Show the answers
        echo "<input name=\"answer\" type=\"radio\" onclick=\"document.poll.submit()\" value=\"".$answer[0]."\" id=\"poll".$answer[0]."\">\n";
        echo "<a href=\"javascript:document.poll.submit()\" onmouseover=\"document.poll.poll".$answer[0].".checked=true\">".$answer[1]."</a><br>\n";
      }
    }
    
    // Close the form
    echo "</form>";
  }
}

function cookiecheck($cookie)
{
  // This function checks if the poll_id in the cookie is the same as the poll_id from the last question
  // if so, it will show the answers, else it will show the last question

  // Collect the last poll_id FROM the DB
  $query = mysql_query("SELECT id FROM poll_questions ORDER BY id DESC LIMIT 0,1");
  $num = mysql_num_rows($query);

  if (empty($num))
  {
    echo "Error: Didn't find last poll!";
  } else {
    // Check if the last poll_id is equal to the poll_id from the cokkie
    $last = mysql_fetch_row($query);

    if ($last[0] == $cookie)
    {
      // Show the results (function)
      showresults($cookie);
    } else {
      // Show the question (function)
      showlast();
    }
  }
}

function showresults($cookie)
{
  // This function will show the results of the poll, it's seen after voting

  // Collect the question from the DB
  $query = mysql_query("SELECT id, question, total_votes FROM poll_questions WHERE id = '$cookie'");
  $num = mysql_num_rows($query);

  if (empty($num))
  {
    echo "Error: Didn't find last poll!";
  } else {
    $question = mysql_fetch_row($query);
    echo $question[1]."<br>\n";
    
    // Antwoorden ophalen
    $query = mysql_query("SELECT id, answer, votes FROM poll_answers WHERE poll_id = '$question[0]' ORDER BY id");
    $num = mysql_num_rows($query);

    if (empty($num))
    {
    	echo "Error: Didn't find answers!";
    } else {
      // Calculate percentage of 1 vote
      $vote = 100 / $question[2];
      
      // Show the answers with a image and a percentage
      while ($answer = mysql_fetch_row($query))
      {
        // Laat de antwoorden zien
        echo $answer[1] . "<br>\n";
        // Uitrekenen hoeveel procent deze heeft
        $percent = round($vote * $answer[2]);
        echo "<img src=\"poll.gif\" height=\"10\" width=\"".$percent."\" alt=\"".$percent."%\" border=\"0\">\n";
        echo $percent . "%<br>\n";
      }
      echo "Total: ".$question[2]." votes\n";
    }
  }
}

mysql_connect("","","");
mysql_select_db("");
showpoll();
?>

===========================================

pollvote.php
<?php
// Connect to the database
mysql_connect("","","");
mysql_select_db("");

// Variables
$answer = $_POST['answer'];
$redirect = $_GET['redirect'];

// Check if $answer isn't empty
if (empty($answer))
{
  header("Location: ".$redirect);
} else {
  // Update poll_answers
  $query = mysql_query("UPDATE poll_answers SET votes = votes +1 WHERE id = '$answer'");
  if (!$query)
  {
    echo "Error: Can't save vote!";
  } else {
    // Collect the poll_id from the DB
    $query = mysql_query("SELECT poll_id FROM poll_answers WHERE id = '$answer'");
    $poll_id = mysql_fetch_row($query);

    // Update total_votes
    $query = mysql_query("UPDATE poll_questions SET total_votes = total_votes + 1 WHERE id = '$poll_id[0]'");
    if (!$query)
    {
      echo "Error: Can't save vote!";
    } else {
      // Set the cookie
      setcookie("poll", $poll_id[0], time()+3600*24*90);
      
      // Send back to $redirect
      header("Location: ".$redirect);
    }
  }
}
?>

===========================================

polladmin.php (NIET BESCHIKBAAR IN HET VOORBEELD!)
[code]<?php

// Connect to the database
mysql_connect("","","");
mysql_select_db("");

// Variables
$action = addslashes($_GET['action']);
if(is_numeric($_GET['step']))$step = $_GET['step'];
if (empty($step)) $step = 1;

if ($action == "add")
{
  if ($step == "1")
  {
    // Here we will make a form. The first <input> is for the question
    ?>
    <form action="polladmin.php?action=add&step=2" method="post">
    Question: <input type="text" name="question" size="50"><br>
    <?php
    // I'm lazy. I don't feel like making like 10 input, so I'll use a for()-loop
    for($i=1;$i<11;$i++)
    {
      echo "Answer ".$i.": <input type=\"text\" name=\"answer".$i."\" size=\"50\"><br>\n";
    }
    
    // End of the form, with a button
    ?>
    <input type="submit" value="Make poll!">
    </form>
    <?php
  } else if ($step == "2") {
    // In this step we will put the question and the answers in the DB

    // First, add the question to the DB
    $question = addslashes($_POST['question']);
    $query = mysql_query("INSERT INTO poll_questions (question) VALUES ('$question')");

    if (!$query)
    {
      echo "Error: Can't write question to the DB!";
      exit;
    }

    // Collect the poll_id of the poll we just made
    $query = mysql_query("SELECT LAST_INSERT_ID() FROM poll_questions");
    if (!$query)
    {
      echo "Error: Can't collect poll_id!";
      exit;
    }
    $poll_id = mysql_fetch_row($query);

    // Again a for()-loopm, now to check answers
    for($i=1;$i<11;$i++)
    {
      // Spoof posted values
      $answer = "answer".$i;
      $answer = $_POST[$answer];

      // If $_POST[$antwoord] is empty, don't do anything
      if (!empty($answer))
      {
        // Save the answer
        $query = mysql_query("INSERT INTO poll_answers (poll_id, answer) VALUES ('$poll_id[0]','$answer')");
        if (!$query)
        {
          echo "Error: Can't write answer to the DB!";
          exit;
        }
      }
    }
    
    echo "Your poll has been created!<br>";
  }
}
?>
<a href="polladmin.php?action=add">Add</a>[/code]