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
https://forums.phpfreaks.com/topic/170445-increasing-a-number-with-a-click/
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..

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..
}

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.