Jump to content


Photo

PHP Voting script (really need help here)


  • Please log in to reply
3 replies to this topic

#1 pinkhooch

pinkhooch
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 29 July 2006 - 02:34 PM

Hi guys, I'm really a newbie to php, hope you guys can help me over here. I'm having problem with my voting scripts that i got it from 3rd party. The voting system currently only allow the voters to vote once as their IP address is being saved in the database and the voter will not be able to vote again.
I will like to modify the script to allow the voters from the same ip to vote once per 24 hours. I search a few tutorial helps which states that setting the cookie will allow same ip to vote once per day.But really newbie and dont understand how it works... Please help me thanks!  :D

<?php
include "connect.php";
$s=$_SERVER["REMOTE_ADDR"];
$ipchecks="SELECT*from P_ip where IP='$s'";
$ipchecks2=mysql_query($ipchecks);
while($ipchecks3=mysql_fetch_array($ipchecks2))
    {
     $isip=$ipchecks3[IP];
    }

if($isip)
    {
     print "You have already voted in this poll";
    }
     
else
    {
        $ID=$_POST['answer'];    
        $ipinsert="Insert into P_ip(IP) VALUES('$s')";
        mysql_query($ipinsert);
      	$vote = "UPDATE P_choices SET votes=votes+1 
		WHERE ID = '$ID'";
        mysql_query($vote);
        print "Thanks for voting, <A href='poll.php'>Back to poll</a>";
    } 


?>


#2 lordphate

lordphate
  • Members
  • PipPipPip
  • Advanced Member
  • 154 posts

Posted 29 July 2006 - 03:27 PM

Okay first off...For third party scripts you might want to go to third party scripts forum...But i will read your code then edit my post with answer. looks like youll need a cronjob

#3 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 29 July 2006 - 04:30 PM

What you need is to edit the database to hold an IP and a time, and then check if the IP exists, where the time is less than 1 day ago.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#4 pinkhooch

pinkhooch
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 30 July 2006 - 06:05 AM

Thanks for the reply!

lordphate: So do i need to repost my question at third party scripts forum?

ShogunWarrior: this means that i need to create another variable (time) in my database of IP ?
How do i write the code in php where the time is 24hrs ago ?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users