DATEDIFF和NOW()mysql_fetch_array错误

时间:2013-10-01 20:11:25

标签: php mysql sql

我正在制作一个剧本。当用户发布内容并且时差小于5分钟时,用户无法发帖。如果超过5分钟,他可以发帖。我认为这段代码可行,但我得到一个mysql_fetch_array错误。我的代码出了什么问题?

if ($db_found)
 {
 $check="SELECT * DATEDIFF(MINUTE, send_time, CURRENT_TIMESTAMP) FROM bloopp WHERE email = '$email' ORDER BY id DESC LIMIT 1";
 $res = mysql_query($check);
 $data = mysql_fetch_array($res, MYSQLI_NUM);
  if($data[0] < 5)
   {
   echo "You posted not so long ago.<br/>";
   }
  else
   {
   $sql="INSERT INTO bloopp (bloopp, browser, medium, send_time, email) VALUES ('$bloopp', '$browser', 'mobile', NOW(), '$email')";
   $result = mysql_query($sql); 
    if($result)
     {
     header('Location: index.php');
     }
     else
     {
      echo "Something has gone wrong. We’re sorry.";
     }
    }
 }
else
 {
 echo "ERROR";
 }

mysql_close();
?>

2 个答案:

答案 0 :(得分:1)

,

后面的*遗失了您
SELECT * DATEDIFF(MINUTE, send_time, CURRENT_TIMESTAMP) 

更改为

SELECT * ,DATEDIFF(MINUTE, send_time, CURRENT_TIMESTAMP) AS `diff` 

在查询

中制作自定义列时,最好给出别名

答案 1 :(得分:0)

SELECT  DATEDIFF(MINUTE, send_time, CURRENT_TIMESTAMP) 

删除*

或保留它,但在之后添加逗号。