1. Home
  2. Computing & Technology
  3. PHP / MySQL

Simple PHP & MySQL Poll

By , About.com Guide

3 of 5

Voting Script - Part 2

//This runs if it is in voted mode
if ( $mode=="voted")
{

//makes sure they haven't already voted
if(isset($_COOKIE[$cookie]))
{
Echo "Sorry You have already voted this month<br>";
}

//sets a cookie
else
{
$month = 2592000 + time();
setcookie(Voted, Voted, $month);

// adds their vote to the database
switch ($vote)
{
case 1:
mysql_query ("UPDATE votes SET first = first+1");
break;
case 2:
mysql_query ("UPDATE votes SET sec = sec+1");
break;
case 3:
mysql_query ("UPDATE votes SET third = third+1");
}

//displays the poll results
pie ();
}
}
The next section of code runs if our voting form has been submitted. It first checks the user to see if they already have a voted cookie. If they do, it does not let them vote again and gives them an error message. However, if they do not, it sets the cookie in their browser and then adds their vote to our database. Finally, it displays the results of the poll by running our pie function.
Explore PHP / MySQL
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Graphics- GD Library
  5. Simple PHP Poll - Graphical PHP Poll - PHP Poll Tutorial

©2009 About.com, a part of The New York Times Company.

All rights reserved.