PHP
  Home arrow PHP arrow Page 5 - Democracy, The PHP Way
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Democracy, The PHP Way
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 21
    2001-04-16

    Table of Contents:
  • Democracy, The PHP Way
  • The Plan
  • Design View
  • Start Me Up
  • Vote Now, Or Forever Hold Your Peace
  • The Number Game
  • Down Memory Lane
  • Cookie-Cutter Code
  • Adding More...

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Democracy, The PHP Way - Vote Now, Or Forever Hold Your Peace


    (Page 5 of 9 )

    Once the form is submitted, "vote.php" takes over to process the vote. This script first checks to ensure that the form has been correctly submitted, by verifying the presence of the $submit and $response variables

    <? // vote.php - record votes // check to ensure that the form has been submitted if (!$submit || !$response) { ?> <html> <head> <basefont face="Arial"> </head> <body bgcolor="white"> <i>Error! Please <a href=start.php>try again</a></i> <? } else { // vote processing code } ?>

    and, assuming that all is well, updates the database to reflect the new vote and displays an appropriate message.

    <? // vote.php - record vote // check to ensure that the form has been submitted if (!$submit || !$response) { // error message } else { // all is well - process the vote ?> <html> <head> <basefont face="Arial"> </head> <body bgcolor="white"> <? // includes include("config.php"); include("common.php"); // connect and update table $connection = mysql_connect($hostname, $user, $pass) or die ("Unable to connect!"); $fieldname = "votes" . $response; $query = "UPDATE $table SET $fieldname = $fieldname+1 WHERE id = $id"; $result = mysql_db_query($database, $query, $connection) or die ("Could not execute query: $query. " . mysql_error()); // query successful,display status message... if ($result) { echo "Thank you for voting. Here are the results so far:<p>"; // code to display results - keep reading! } // or error in query - display error message else { echo "<i>Error! Please <a href=start.php>try again</a></i>"; } // close connection mysql_close($connection); } ?> </body> </html>

    As you can see, the value of the $response variable is used to determine which option field is updated with the user's vote.

    This article copyright Melonfire 2001. All rights reserved.

    More PHP Articles
    More By Vikram Vaswani, (c) Melonfire


     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT