Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/261070-storing-clicks-on-a-button-how/
Share on other sites

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);
}

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.

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.

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.