for mySQL, the table would look like... CREATE TABLE polls( pollID INT NOT NULL AUTO_INCREMENT, ipAddress VARCHAR (50) NULL, insertTime DATETIME NULL, etc... PRIMARY KEY (pollID) ); =========================================================== the code would look like...
$statement = "select pollID from polls where insertTime > (now() - INTERVAL 1 HOUR)"; //see mySQL date time functions for a description of this $result = mysql_query($statement); $rowsReturned = mysql_num_rows($result); if($rowsReturned){ print "Sorry you already voted in the last hour"; }else{ "insert into polls (ipAddress,insertTime) values ('$ipAddress',now())"; } P.S. - "now()" is a database function that will insert the time for you (mySQL is usually yyyy-dd-mm hh:mm:ss) -----Original Message----- From: wade [mailto:[EMAIL PROTECTED]] Sent: Wednesday, October 02, 2002 2:56 PM To: Vincent, Jason [BRAM:1334:EXCH] Subject: Re: [PHP-DB] Difference in time MYSQL Here is a sample of what I am doing $ip = $_SERVER['REMOTE_ADDR']; $time_now = mktime(); // open connection to database $connection = mysql_connect($hostname, $user, $pass) or die ("Unable to connect!"); // get the IP and stored DB time $query = "SELECT ip_address, server_time FROM stats WHERE ip_address = '$ip'"; $result = mysql_db_query($database, $query, $connection) or die ("Error in query: $query. " . mysql_error()); $row = mysql_fetch_array($result); $get_ip = $row['ip_address']; $get_server_time = $row['server_time']; // close connection mysql_close($connection); mysql_free_result($result); if ($ip == $get_ip) { $connection = mysql_connect($hostname, $user, $pass) or die ("Unable to connect!"); $query="select * from stats where server_time > 'now()- 1 hour' and ip_address = '$ip'"; $result = mysql_db_query($database, $query, $connection) or die ("Error in query: $query. " . mysql_error()); $row = mysql_fetch_array($result); $get_ip2 = $row['ip_address']; $get_server_time2 = $row['server_time']; // close connection mysql_close($connection); mysql_free_result($result); if ($get_server_time2) { echo "Sorry cannot vote"; exit; } } Jason Vincent wrote: what kind of database are you using? -----Original Message----- From: wade [mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> ] Sent: Wednesday, October 02, 2002 2:47 PM To: Vincent, Jason [BRAM:1334:EXCH] Subject: Re: [PHP-DB] Difference in time One question on this issue. What should I store in the database mktime( ). time( )? Jason Vincent wrote: > yeah - the mktime function is returning unix style time (seconds since > 1970) which is why only the last few numbers are changing. I would > recommend letting the database decide who is able to submit... i.e. > > select * from database where lastSubmitDate > 'now()- 1 hour' and IP = > '$ipaddress' > > if there is a returned record from the database, you know that this > person has made a submission in the last hour. Otherwise, let them > submit again > > Obviously, you will need to figure out the sytax for the now() -1 hour > part depending on your database. > > -----Original Message----- > From: wade [mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> ] > Sent: Wednesday, October 02, 2002 1:29 PM > To: [EMAIL PROTECTED] > Subject: [PHP-DB] Difference in time > > Hello all, > > I am fighting a time issue(don't we all). I have a online poll set up. > I need a way to stop a person from submitting more than once an hour. > As of now I have the time .. mktime( > ) .. being stored in a database along > with the users IP. > > I want to be able to say if 1 hour has passed from the time .. mktime( > ) .. that is stored in the db they can vote once again. This also has > to account that if someone goes to the poll tomorrow at the same time > (same > hour) the script knows it's a different hour and different day. > > Scenario: I submit to the poll at 12:00 PM, one hour from now will be > 1:00 PM and I can submit again. Now lets say it's 12:00 PM the next > day. The database stored time will say 12:00 PM of the day before, It > will not let me submit because it thinks that it has to be at least > 1:00 PM before I can submit again. Which is wrong. > > I was trying to use the mktime( ) function but it keeps giving me > these results.(( 1033578795 )) The last few numbers change but the > first few (that as suppose to be the hour) does not change? mktime(int > hour, int minute, int second, int month, int day, int year). How can I > use this mktime( ) function to do what I need it to? Am I going in the > wrong direction? > > Thank you very much > Wade > > -- > Should you have any questions, comments or concerns, feel free to call > me at 318-338-2033. > > Thank you for your time, > > Wade Kelley, Design Engineer > ================================================ > Bayou Internet...(888) 30-BAYOU...http://www.bayou.com <http://www.bayou.com> Mississippi > Internet...(800) MISSISSIPPI...http://www.mississippi.net <http://www.mississippi.net> > Vicksburg Online...(800) MISSISSIPPI...http://www.vicksburg.com <http://www.vicksburg.com> > ================================================ -- Should you have any questions, comments or concerns, feel free to call me at 318-338-2033. Thank you for your time, Wade Kelley, Design Engineer ================================================ Bayou Internet...(888) 30-BAYOU...http://www.bayou.com <http://www.bayou.com> Mississippi Internet...(800) MISSISSIPPI...http://www.mississippi.net <http://www.mississippi.net> Vicksburg Online...(800) MISSISSIPPI...http://www.vicksburg.com <http://www.vicksburg.com> ================================================ -- Should you have any questions, comments or concerns, feel free to call me at 318-338-2033. Thank you for your time, Wade Kelley, Design Engineer ================================================ Bayou Internet...(888) 30-BAYOU...http://www.bayou.com <http://www.bayou.com> Mississippi Internet...(800) MISSISSIPPI...http://www.mississippi.net <http://www.mississippi.net> Vicksburg Online...(800) MISSISSIPPI...http://www.vicksburg.com <http://www.vicksburg.com> ================================================