Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: PHP  |  size: 1.11 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.     session_start();
  3.    
  4.     if(isset($_POST['submit']))
  5.     {
  6.         if ($_POST['first']=='yes'){
  7.             $id = 1;
  8.         }
  9.         else if ($_POST['first']=='no'){
  10.             $id = 2;
  11.         }
  12.         $upd_query = mysql_query("UPDATE poll SET votes=votes+1 WHERE id=".$id);
  13.        
  14.         $_SESSION['show_result'] = true;
  15.        
  16.         header("Location: polls.php");  
  17.     }
  18. ?>
  19. <form method="POST">
  20. Да<input name = "first" type = "radio" value = "yes"><br>
  21. Нет<input name = "first" type = "radio" value = "no"><br>
  22. <input name = "submit" type = "submit" value = "Проголосовать">
  23. </form>
  24. <?php
  25.     if(isset($_SESSION['show_result']))
  26.     {
  27.         unset($_SESSION['show_result']);
  28.        
  29.         mysql_connect("localhost", "root", "preved");
  30.         mysql_select_db("vmss");
  31.         $query = mysql_query("SELECT description, votes FROM poll");
  32.         while($row = mysql_fetch_array($query))
  33.         {
  34.             echo "Вариант: ".$row['description']."<br>\n";
  35.             echo "Проголосовало: ".$row['votes']."<br><br>\n";
  36.         }
  37.     }
  38. ?>