MySQL and PHP check for already submitted data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alexphd
    New Member
    • Dec 2006
    • 19

    MySQL and PHP check for already submitted data

    I've been creating this webapp and for some weird reason I cant get this part to work. What I'm trying to do is check for a match on the username and startdate. If there is a match then that user has already submitted his/her timesheet.

    Code:
    $check = mysql_query("SELECT * FROM timesheets WHERE username = '$username' AND startdate='$start_date'");
    	
    if($check != 0)
    {
    	die("<p>Sorry, that timesheet has been submitted.</p>");
    }
    Thanks in advance

    Alex
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Yo alex!

    Try using mysql_num_rows( ). It returns the number of rows affected by your query.

    [php]
    $_Query = mysql_query("SE LECT * FROM `tbl_name` WHERE `row_1` = '{$_var1}'";

    if(mysql_num_ro ws($_Query) > 1)
    {
    # there is a row that fits the query
    echo "Already submitted";
    }
    else
    {
    # there are 0 rows affected
    # do query
    }
    [/php]
    Regards!

    Comment

    • alexphd
      New Member
      • Dec 2006
      • 19

      #3
      Thanks, that worked I just had to change > 1 to > 0 zero, because if I submitted a the time sheet and then hit the back button for some reason it would reenter the time even though it was already there. But changing it to zero fixed the problem.

      Thanks for your help.

      Comment

      Working...