Button with limited clicking (2)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
egturnkey
Forum Commoner
Posts: 34
Joined: Sun Jul 26, 2009 7:35 pm

Button with limited clicking (2)

Post by egturnkey »

Hello friends,

This is the second thread and we almost done 90% of the idea

" consider a button , it must be limited on clicking that button only 20 times per person ( IP ) per day "

which mean if someone click on it 20 times , must wait to next day to click on it more clicks


here is the example to download
( index.php - config.php - db.sql )

http://www.egcss.com/ex2.rar



or reivew the coder as following
index.php

Code: Select all

 
<?php
include "config.php";
 
$time = date("m/d/y");
mysql_query("INSERT INTO `ip_table` (`ip`,`timestamp`) VALUES ('".mysql_real_escape_string($_SERVER['REMOTE_ADDR'])."',$time)");
 
$date = date("m/d/y");
$qq = mysql_query("SELECT * FROM ip_table WHERE ip='$_SERVER[REMOTE_ADDR]' AND date='$date'") or die(mysql_error());
$num = mysql_num_rows( $qq ) or die(mysql_error());
 
if($num > 20) {
echo "You can't click that. You've already clicked it 20 times.";
} else {
echo "You can click that.";
}
?>
 
config.php

Code: Select all

 
<?
$dbhost = "localhost";
$dbuser = "username";
$dbpass = "password";
$dbname = "dbname";
@mysql_connect($dbhost,$dbuser,$dbpass);
@mysql_select_db($dbname);
?>
 

database.sql

Code: Select all

 
CREATE TABLE ip_table (
IP varchar(255),
date varchar(255),
timestamp varchar(255)
) TYPE=MyISAM;
 

WE STILL HERE ERROR

- It didn't shown the error msg as it should be after the 20 clicking times

however it record in database everything as it should be IP - TIME

so can anyone please check it out and fix it .

thanks in advance
iamngk
Forum Commoner
Posts: 50
Joined: Mon Jun 29, 2009 2:20 am

Re: Button with limited clicking (2)

Post by iamngk »

when you are inserting new record, you are storing current date in 'timestamp' column.
INSERT INTO `ip_table` (`ip`,`timestamp`)
when you are selecting, you are comparing with 'date'
WHERE ip='$_SERVER[REMOTE_ADDR]' AND date='$date'")
that is the problem.
Post Reply