0

I'm currently working on a script. When a user posts something and the timedifference is smaller than 5 minutes, the user cannot post. If bigger than 5 minutes, he can make a post. I thaught this code would work, but I get a mysql_fetch_array error. What is wrong with my code?

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();
?>
4

2 回答 2

1

You are missing with , right after *

SELECT * DATEDIFF(MINUTE, send_time, CURRENT_TIMESTAMP) 

change to

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

its better to give alias when your are making custom column in query

于 2013-10-01T20:13:02.753 回答
0
SELECT  DATEDIFF(MINUTE, send_time, CURRENT_TIMESTAMP) 

Remove the *

Or keep it but add a comma after.

于 2013-10-01T20:14:40.813 回答