Welcome, Guest. Please login or register.
Did you miss your activation email?
May 25, 2012, 10:00:22 PM

Login with username, password and session length
Search:     Advanced search
Interested in joining the WebsiteBaker team?
For more Information read here or on our new website.
155529 Posts in 21713 Topics by 7737 Members
Latest Member: chris85
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: PLease help with this code!  (Read 385 times)
sayf_theone

Offline Offline

Posts: 21


« on: November 16, 2009, 09:45:42 PM »

Quote
<?php
  include "config.php";
  
  if(!empty($_POST['id_answer']))
  {
    $id_answer = $_POST['id_answer'];

    $forward = getenv(HTTP_X_FORWARDED_FO R);
    $ip = urldecode(getenv(HTTP_CLIENTIP));
    if (($forward != NULL)&&($forward != $REMOTE_ADDR))  $ip = $ip."/".$forward;
  
    $isip = "SELECT * FROM poll_ip
             WHERE ip='$ip'
             AND puttime>date_sub(now(), interval '2' minute)";
    $ipresult = mysql_query($isip);
    
    $delip = "DELETE FROM poll_ip
              WHERE puttime<date_sub(now(),interval '2' minute)";
    mysql_query($delip);
    if($ipresult)
    {
      if(mysql_num_rows($ipresult)<1)
      {
        
        mysql_query("INSERT INTO poll_ip VALUES(0,'$ip',now())");
      
        $query = "select hit from answer where id_answer=$id_answer";
        $num = mysql_query($query);
        if($num)
        {
          $number = mysql_fetch_array($num);
          $query = "UPDATE answer SET hit=".($number['hit']+1)." WHERE id_answer=$id_answer";
          mysql_query($query);
        } else puterror("Ошибка при обращении к блоку голосования");
      }
    }
  }
 
  $pol = mysql_query("SELECT * FROM poll WHERE archive=0 AND hide=0");
  if ($pol)
  {
    $poll = mysql_fetch_array($pol);
    echo $poll['name']."<br>";
  
    $query = "SELECT * FROM answer
              WHERE id_poll=".$poll['id_poll']."
              ORDER BY pos";
    $total = "SELECT SUM(hit) FROM answer WHERE id_poll=".$poll['id_poll'];
    $ans = mysql_query($query);
    $tot = mysql_query($total);
    if($ans && $tot)
    {
      $totl = mysql_fetch_array($tot);
      $totalhits = $totl['SUM(hit)'];
      if($totalhits == 0) $totalhits = 1;
      echo "<table>";
      while($answer = mysql_fetch_array($ans))
      {
        echo "<tr>
               <td>".$answer['name']."</td>
               <td>".$answer['hit']."</td>
               <td>".sprintf("%01.1f%s", $answer['hit']/$totalhits*100,'%')."</td>
              </tr>";
      }
      echo "</table>";
      echo "Общее число проголосовавших составляет: ".$totl['SUM(hit)']."<br>";
      echo "<a href=archive.php>Архив голосований</a><br>";
    } else puterror("Ошибка при обращении к блоку голосования");
  } else puterror("Ошибка при обращении к блоку голосования");
?>

and the config file is
Quote
<?php

  $dblocation = "localhost";
  
  $dbname = "poll";
 
  $dbuser = "root";
 
  $dbpasswd = "0000";

  $version = "2.0.1";

  $dbcnx = @mysql_connect($dblocation,$dbuser,$dbpasswd);
  if (!$dbcnx) {
    echo( "<P>В настоящий момент сервер базы данных не доступен, поэтому корректное отображение страницы невозможно.</P>" );
    exit();
  }

  if (! @mysql_select_db($dbname,$dbcnx) ) {
    echo( "<P>В настоящий момент база данных не доступна, поэтому корректное отображение страницы невозможно.</P>" );
    exit();
  }
 
  function puterror($message)
  {
    echo("<p>$message</p>");
    exit();
  }
?>



when i add this code to the template index.php it don't work Sad

but when i saved it in php file and opened it it works.

please tell me what the problem is..
« Last Edit: November 16, 2009, 09:47:25 PM by sayf_theone » Logged
WebBird
Guest
« Reply #1 on: November 17, 2009, 11:12:17 AM »

You may tell us first what "don't work" means?
Logged
sayf_theone

Offline Offline

Posts: 21


« Reply #2 on: November 18, 2009, 09:15:22 PM »

this code for poll. it don't show the anything.

but when i save it , its work normaly.

but in the template page down't work.
Logged
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!