Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2010
    Thanked 0 Times in 0 Posts

    Question mysql limit submission

    I am fairly new at mysql and I was wanting to use the row 'time' in my database, which is a timestamp, to limit the number of times a person can submit a form to that database.

    mysql_query("SELECT count(*) FROM table1 WHERE time <= CURDATE()");
    if (count <= 1) {
    //successfully input to database...
    I know this is not correct. Any help is appreciated.

  2. #2
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Thanked 997 Times in 994 Posts
    Mysql uses DATE and DATETIME and TIMESTAMP for it's time. If you are going to limit uploads by the day use DATE if by the hour use DATETIME.

    PHP does things different, but we can use date() for both mysql forms.
    read this page http://www.php.net/manual/en/function.date.php

    For what you want to do you first must store a date when user uploads.
    And then when he uploads again you retrieve that date and compare.

    $phpdate = date('Y-m-d');
    $query = "
    SELECT time
    FROM table1
    WHERE User = 'PUT Users name/ID here'
    $results = mysql_query($query);
    $row = mysql_fetch_row($results);
    if($row[0] == $phpdate)
    	echo 'match'.'<br />'; // CAN NOT UPLOAD - change the message to what you want
    	echo 'No match'.'<br />';  // CAN UPLOAD TODAY - do it here
    $query = "UPDATE table1
    SET time = '$phpdate'
    $results = mysql_query($query);


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts