i have a form where the employee should type in-time(attendance)........
i want the user to insert only once in a day.....
if he tries to insert the data in same day the it should display error message.....

please display your code..

<form name="fm3" method="post" action="date1.php">
<table>
<tr>
<td>splendor Id</td><td><input type="text" name="id3" size="20" value=<?php print "$_SESSION[spid]";?> readonly></td>
</tr>
<tr>

<td>Day</td><td><input type="text" name="day" size="20" value=<?php
$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y")); 
echo "".date("Y/m/d", $tomorrow);
?> readonly></td>
</tr>
<tr>
<td>Time</td><td><input type="text" name="tm1" size="20" value=<?php
   
      $time_now=mktime(date('h'),date('i'),date('s'));
   
      echo "".date('h:i:s A',$time_now);
  
      ?> readonly></td>
</tr>
<?php $_SESSION[time] = "$time_now";?>

<tr>
<td><input type="Submit" name="Submit" value="submit"></td>
</tr>
</form>

database insertion

<?php
$id3=$_POST['id3'];


$day=$_POST['day'];



$tm1=$_POST['tm1'];

$hostname = "localhost";
$username = "";
$password = "";
$dbid = "";
$link=mysql_connect($hostname, $username, $password);
mysql_select_db($dbid) or die("unable to connect");

if (isset($_REQUEST['Submit'])) 
{ 
mysql_query("INSERT INTO attend(spid,day1,time1)VALUES('$id3','$day','$tm1')") or die("ERROR:".mysql_error());
echo "THANKS ";
}

mysql_close($link);
?>

if (isset($_REQUEST['Submit'])) 
{ 

$query="Select * from attend
             WHERE spid='$id3'
             AND day1='$day'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if ($num==0)//if there are no match then insert record...
     {    
     mysql_query("INSERT INTO attend(spid,day1,time1)VALUES('$id3','$day','$tm1')") or           die("ERROR:".mysql_error());
     echo "THANKS ";
     }
else
    {
    //do nothing or echo something like "you have already logged in"....
    }
}

I think you can put a trigger which will ensure spid+date is unique. That is insertion will fail automatically.

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.