polling system

  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

are there any tutorials out there on how to create a simple polling system...

all the tutorials i can find are for making more than one poll.... i juust want one simple polling system :(
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

well if you have no idea how to do this ask again but the basic, make your form a varible like so

PHP Code: [ Select ]
$form = "<form action='$PHP_SELF' method='post'>";
 
$form.= "<input type='radio' name='option' value='value1'>";
 
$form.= "<input type='radio' name='option' value='value2'>";
 
$form.= "<input type='radio' name='option' value='value3'>";
 
$form.= "<input type=submit name='submit' value='Vote'></form>";
 
 
  1. $form = "<form action='$PHP_SELF' method='post'>";
  2.  
  3. $form.= "<input type='radio' name='option' value='value1'>";
  4.  
  5. $form.= "<input type='radio' name='option' value='value2'>";
  6.  
  7. $form.= "<input type='radio' name='option' value='value3'>";
  8.  
  9. $form.= "<input type=submit name='submit' value='Vote'></form>";
  10.  
  11.  


now for submit to a database

PHP Code: [ Select ]
#ON FIRST OPENING DISPLAY THE FORM
 
if( !$submit) { $msg = $form; } else
 
 
 
#OR REDISPLAY A MESSAGE AND THE FORM IF COMPLETE
 
if( !$option)
 
{ $msg = "<b>Please select an option before voteing.</b><br><br>";
 
$msg.= $form; } else
 
 
 
#OR ADD THE FORM DATA TO THE POLL DATABASE TABLE
 
{ $conn = @mysql_connect("localhost", "$db_user", "$db_password")
 
     or die("could not connect to MySQL");
 
  $db = @mysql_select_db("$db_name",$conn)
 
   or die("Could not select database"); #select database
 
 $sql = "insert into `poll`
 
  (`option`,`ip`) values
 
  ('$option','$REMOTE_ADDR') "; #create the query
 
  $result = @mysql_query($sql,$conn)
 
    or die("Could not execute query"); #execute the query
 
  if($result) { echo("Thank you for your vote."); }
 
 }
 
 echo($msg);
  1. #ON FIRST OPENING DISPLAY THE FORM
  2.  
  3. if( !$submit) { $msg = $form; } else
  4.  
  5.  
  6.  
  7. #OR REDISPLAY A MESSAGE AND THE FORM IF COMPLETE
  8.  
  9. if( !$option)
  10.  
  11. { $msg = "<b>Please select an option before voteing.</b><br><br>";
  12.  
  13. $msg.= $form; } else
  14.  
  15.  
  16.  
  17. #OR ADD THE FORM DATA TO THE POLL DATABASE TABLE
  18.  
  19. { $conn = @mysql_connect("localhost", "$db_user", "$db_password")
  20.  
  21.      or die("could not connect to MySQL");
  22.  
  23.   $db = @mysql_select_db("$db_name",$conn)
  24.  
  25.    or die("Could not select database"); #select database
  26.  
  27.  $sql = "insert into `poll`
  28.  
  29.   (`option`,`ip`) values
  30.  
  31.   ('$option','$REMOTE_ADDR') "; #create the query
  32.  
  33.   $result = @mysql_query($sql,$conn)
  34.  
  35.     or die("Could not execute query"); #execute the query
  36.  
  37.   if($result) { echo("Thank you for your vote."); }
  38.  
  39.  }
  40.  
  41.  echo($msg);
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

thats only the submit ill figger out the display later or if anyone else has a better way

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 68 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.