Advertisement
DrWhat

Limit user activity per month with PDO

Mar 10th, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1. <?PHP
  2. require ("include/db.inc.php");
  3. $user_id = 1;
  4. $search = $db->prepare("SELECT `searched` FROM `search` WHERE `user_id` =:user_id");
  5. $search->bindValue(':user_id', $user_id, PDO::PARAM_INT);
  6. $search->execute();
  7. $result = $search->fetch(PDO::FETCH_ASSOC);
  8. echo "<pre>", print_r($result), "</pre><br>";
  9. if ($result['searched'] >= 10){
  10.     echo 'you have reached your search limit for this month<br>';
  11. }
  12. $addsearch = $db->prepare("UPDATE `evomap`.`search` SET `searched` = :searched + 1 WHERE `search`.`id` =:user_id;");
  13. $addsearch->bindValue(':user_id', $user_id, PDO::PARAM_INT);
  14. $addsearch->bindValue(':searched', $result['searched'], PDO::PARAM_INT);
  15. $addsearch->execute();
  16. echo 'DEBUGGING';
  17. echo'<br><pre>', print_r($db->errorInfo()), '<pre>';
  18. echo "Number of results: ", $search->rowCount(), "<br>";
  19. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement