如果今天插入记录,我该如何进行验证?

时间:2014-08-26 08:08:59

标签: php mysql

$days = date('Y-m-d ', mktime($count['time_in']));
$date_today = date('Y-m-d');

if ($days != $date_today)  {
    $sql = "INSERT INTO login_details (time_in, user_id) VALUES (CURRENT_TIMESTAMP, '".$_SESSION['user_id']."') ";
    $result =  mysql_query($sql);

} else{         
   echo "<h3 align=center>Already exist!</h3>";
   header ('refresh: 3; URL = index.php?page=timerecord');
}

1 个答案:

答案 0 :(得分:-2)

time_in列应该在数据库中应该是datetime数据类型。

$date_today = date('Y-m-d');

$selectSql=mysql_query("SELECT count(*) as logincount from login_details where time_in=date(now())");
$countLogin=mysql_result($selectSql,0,'logincount');

if($countLogin>0){
} else {
   $sql = mysql_query("INSERT INTO login_details (time_in, user_id) VALUES ('".$date_today."', '".$_SESSION['user_id']."')");
}