LegacyP7 Posted April 16, 2012 Share Posted April 16, 2012 Hello PHPFreaks, I have emerged yet again with another question. I currently have a fully operational Minecraft Voting for Diamonds script (Don't turn away because you saw Minecraft, this has nothing to do with it), and want to enhance it; though a 'Top Voters' list. Now, basically the script goes like this Login Page > Main Page with links > Rewarding Script > thank you message. On the main page with links, once all links are clicked on, you click a 'Get Rewarded' button. I want to track who clicks this, and how many times a month it is clicked by them. Only 1 click on the button is allowed per day, with the use of cookies. This means the maximum amount of clicks on it per month, per user would be something around 30. I store the players usernane in the cookies, and if they have voted today, but that is all. The Top Voters list would look something like this: Userwhatever - 6 Votes Blarg - 4 votes Someone - 2 votes And so on... I want an ordered list of users which have voted that month. 'Votes', would be the amount of times that 'Get Rewarded' had been clicked. How can I make this? I will also require it to reset all votes of the first of every month, how do I do this? Many thanks! Quote Link to comment https://forums.phpfreaks.com/topic/261070-storing-clicks-on-a-button-how/ Share on other sites More sharing options...
chriscloyd Posted April 17, 2012 Share Posted April 17, 2012 you use a database? You can set up a table for Votes say your link is mydomain.com/?vote=id on the page that actually does the voting create a script to insert the vote for example <?php //clean id $id = mysql_real_escape_string($_GET['id']); //check if it has been voted on already $Check = "SELECT * FROM Votes WHERE id = '$id}'"; $Query = mysql_query($Check); if ($Query) { $Update = "UPDATE Votes SET votes = votes + 1 WHERE id = '{$id}'"; mysql_query($Update); } else { $Insert = "INSERT INTO Votes (`id`,`votes`) VALUES ('{$id}','1')"; mysql_query($Insert); } Quote Link to comment https://forums.phpfreaks.com/topic/261070-storing-clicks-on-a-button-how/#findComment-1337968 Share on other sites More sharing options...
bspace Posted April 17, 2012 Share Posted April 17, 2012 rewards based on storing info in cookies? i think you need to rethink this and do it with php and your database Quote Link to comment https://forums.phpfreaks.com/topic/261070-storing-clicks-on-a-button-how/#findComment-1337971 Share on other sites More sharing options...
LegacyP7 Posted April 17, 2012 Author Share Posted April 17, 2012 you use a database? You can set up a table for Votes say your link is mydomain.com/?vote=id on the page that actually does the voting create a script to insert the vote for example <?php //clean id $id = mysql_real_escape_string($_GET['id']); //check if it has been voted on already $Check = "SELECT * FROM Votes WHERE id = '$id}'"; $Query = mysql_query($Check); if ($Query) { $Update = "UPDATE Votes SET votes = votes + 1 WHERE id = '{$id}'"; mysql_query($Update); } else { $Insert = "INSERT INTO Votes (`id`,`votes`) VALUES ('{$id}','1')"; mysql_query($Insert); } Hello, many thanks for the reply. When it comes to anything with MySQL, I am a complete newbie. I basically want a PHP page with a giant table, two colums wide. The left for users, the right for votes, or clicks on that button. After that button is clicked, it goes through a script called setvoted.php, and this sets a cookie, which tells the script that the user has voted today. The Get Rewarded button only works when that cookie is not set. So I believe that there would be no need for the else and if in your statement. Correct me if I am wrong. I have never used MySQL before, so I am wondering how their username can be added to this table on another PHP document, alongside their votes. Thanks. And to the above comment, yes, once I get my head around MySQL, I will make it store their IP to, so that it can check for cookies, their IP, and their username. This would further prevent any cheating. Quote Link to comment https://forums.phpfreaks.com/topic/261070-storing-clicks-on-a-button-how/#findComment-1338038 Share on other sites More sharing options...
KevinM1 Posted April 17, 2012 Share Posted April 17, 2012 Cookies can be erased/modified by the user. It's trivial to do it, too. Never use them for something like this. Quote Link to comment https://forums.phpfreaks.com/topic/261070-storing-clicks-on-a-button-how/#findComment-1338067 Share on other sites More sharing options...
batwimp Posted April 17, 2012 Share Posted April 17, 2012 If you're going to do anything with PHP, it's really in your best interest to learn to implement a database (usually MySQL). You'll be happy you did, and there will be an exponential increase in the amount of stuff you can do with PHP. It's well worth the time. Quote Link to comment https://forums.phpfreaks.com/topic/261070-storing-clicks-on-a-button-how/#findComment-1338131 Share on other sites More sharing options...
LegacyP7 Posted April 17, 2012 Author Share Posted April 17, 2012 I understand that cookies can be wiped, and that is why I wish to know how I can store their usernames and IP's? Also, yes, MySQL would be a major help, and that is why I wish for you to help me out with this My earlier message explains all I want to do. Quote Link to comment https://forums.phpfreaks.com/topic/261070-storing-clicks-on-a-button-how/#findComment-1338257 Share on other sites More sharing options...
KevinM1 Posted April 18, 2012 Share Posted April 18, 2012 I understand that cookies can be wiped, and that is why I wish to know how I can store their usernames and IP's? As been said, you store them in a database, along with other user info. Also, yes, MySQL would be a major help, and that is why I wish for you to help me out with this My earlier message explains all I want to do. The problem is that since you don't know how to use a database at all, it's hard to point you in the right direction. Teaching the fundamentals just isn't a good fit in a message board format. I suggest you look at some of the resources found in this thread, along with any other tutorials you can find that will illustrate how to create tables and run basic queries (these three tutorials may help) so you can grasp the basics. Trying to create a database design that does what you want will be nearly impossible unless you understand what's going on. That can only happen if you take the time to learn the basics. Quote Link to comment https://forums.phpfreaks.com/topic/261070-storing-clicks-on-a-button-how/#findComment-1338385 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.