Jump to content

Increasing a number with a click.


cnthiesen

Recommended Posts

Hi! I am just beginning to learn PHP, and I want to create something that I think is very simple but I have no idea how to go about.

On my webpage, I would like my viewers to be able to simply click on one button and become supporters of my websites cause. Also I would like to display the number of supporters somewhere on the site. and if this is not to difficult, restricting it to one supporter per IP address. I have access and know a bit mysql, and i am guessing that it will be involving that?

Any help will be much appreciated!

 

Link to comment
Share on other sites

You can look at this example code here..

http://forums.tizag.com/showthread.php?t=4167

 

It's for a page hit counter, but you can just modify it to be a counter for the support causes..

 

<form action="counter.php" method="post">

...

</form>

 

Is what you can create for the button, in counter.php write the code to place them in the database, creating a table alongside to see if anyone already with the same IP joined..

Link to comment
Share on other sites

Store each IP address that has clicked in a table. And when it's click make sure it's not in the table, if it's not then increment a number.

 

$result = mysql_query("SELECT ip FROM `clicked_ips` WHERE ip='$ip'");
if(!mysql_num_rows($result))
{
     //Increment a number
     //Then Add them to the table
     mysql_query("INSERT into `clicked_ips` (ip) VALUES('$ip')");
}
else
{
    //Error: You have already clicked this..
}

Link to comment
Share on other sites

Hi! Thanks for the help. I got the basic counter to work great with my support the cause. However, still having trouble setting up the storage of ip address'. When I said I knew a bit of mysql, i should  rather just have stated I knew what it was and the basic principles of it. I would appreciate if you could explain how to create and implement the table that would store each ip address to the basic counter. Hope I am being clear of what I don't understand.

And thanks again!

Link to comment
Share on other sites

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.