|
|
||||||
|
||||||
| Index Link To US Private Messages Archive FAQ RSS | ||||||
| Database Discussion Forum This is the place to find help resolving those nagging questions you have about implementing and using all kinds of databases. Need help writing a query? Need an opinion on Oracle? Post here! |
Share Thread: & Tags
|
||||
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
I have a voting script on one of my sites and it works fine, but i want to block people from multiple voting.
i figured the best way was to record the ip address and then block that ip from voting for a particular person again. This is what part the code on the vote process page looks like: // get stuff from form $ips = $_GET["ip"]; $who = $_GET["manme"]; $wherefromwas = $_GET["whereami"]; // Make a MySQL Connection $link = mysql_connect("localhost","root",""); mysql_select_db("unrated1",$link); $query = "SELECT * FROM votes WHERE votes.mname = '$who' "; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ //echo $row['mname']. " - ". $row['ip']; //echo "<br />"; if ($row['ip'] == $ips ){header("refresh: 0; url=$wherefromwas"); } } basically this is what i want this to do: let say you want to vote for me. it should get all of the ip's (other votes for me) and check to see if you have voted for me before if so then return you back to the page. (don't allow/record the vote) if not it should continue to process the vote which is basically a few more if's and else to make sure the the voting form is completed and record the vote. i can't get it to work properly. it records a new vote every time. what am i doing wrong here? If you want to see this in action send me a message and ill send you the link and show you all the vote process code
__________________
It's better to do business with me than against me! |
|
|||
|
Thanks wige.
I thought about that. The votes are really just for entertainment but i want it to be somewhat fair. if a user does get a new ip address that fine. Thats just another unique vote. I have looked around and made some changes to the code $link = mysql_connect("localhost","root",""); mysql_select_db("unrated1",$link); $query = "SELECT * FROM votes WHERE votes.mname = '$who' "; $result = mysql_query($query) or die(mysql_error()); //while($row = mysql_fetch_array($result)){ if ($row['ip'] == $ips) { header("refresh: 0; url=nope.php"); } else { while($row = mysql_fetch_array($result)) { header("refresh: 0; url=yes.php"); }} i though this would work but no. Ill check into making the IP column unique. Good Idea.
__________________
It's better to do business with me than against me! Last edited by jazzmatazz2005; 06-26-2009 at 02:36 PM. |
|
||||
|
A delicate problem. There should be better solutions that logging Ip's.
|
|
||||
|
If you know opera:config (put it in the address field) you can change default settings to surf "almost" invisible.
__________________
Mini Network:: Financial information at your fingertips Learn object oriented programming where it started Last edited by kgun; 06-26-2009 at 03:21 PM. |
|
|||
|
thanks williamc and kgun. i dont want anything to complicated. like i said its only for entertainment.
maybe i wasnt clear with what my voting form does. for every person thats active (over 400 so far) there are three categories that you vote on. in all three categories you basically vote 1-5 in the process page it checks to make sure you filled in all three categories and saves all the information along with your IP. In my simple code i thought you could get all the votes for "a" active person into an arrow and check to see if the user has voted for this active person before. if so return the user back to the page and save the save else save all the information then return the user back to the page where they can can then move on to the next person and the process starts all over again. I tried making the IP column unique but now it dosn't allow anymore votes from the same person at all. when your vote for 1 person thats it, you cant vote anymore. Thats no fun there are over 400 people to vote on.
__________________
It's better to do business with me than against me! |
|
||||
|
I agree with kgun and william, you will probably get something more effective using cookies.
As far as allowing multiple votes, the only mechanism I can think of is to do a count, then based on that count determine whether or not to add the new vote to the list. "SELECT COUNT(*) FROM votes WHERE ip = '".$_SERVER['REMOTE_ADDR']."' AND votes.mname = '$who'" As long as the count is zero, this user has not voted for this person yet.
__________________
The best way to learn anything, is to question everything. |
|
|||
|
This might be nothing, but I noticed that the GET array variable you're assigning to $who is $_GET["manme"] and in your select statement you're comparing to a database field named mname. Is this a typo?
|
|
||||
|
A quick glance makes me think that unless the first IP in the array matches the one for the new voter then it will drop through, without checking the rest, and be accepted.
Try While loop stepping through existing ips { if ip match { set bad flag drop out of while loop } } if bad flag set { bad vote } else { thanks } Last edited by Uncle Dog; 06-26-2009 at 09:43 PM. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
WebProWorld |
Advertise |
Contact Us |
About |
Forum Rules |
MVP's |
Archive |
Newsletter Archive |
Top |
WebProNews
WebProWorld is an iEntry, Inc. ® site - © 2009 All Rights Reserved Privacy Policy and Legal iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 |