mkaplan

Untitled

Apr 10th, 2011
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.23 KB | None | 0 0
  1. if( !isset($_SESSION["p_id"])){
  2.     echo "Please log in before attempting to rate messages";
  3.     die();
  4.     }
  5. if( !isset($_POST["m_id"])){
  6.     echo "Invalid message ID";
  7.     die();
  8.     }
  9. if( !isset($_POST["rating"])){
  10.     echo "Invalid rating";
  11.     die();
  12.     }
  13.  
  14. $link = connectDB();
  15. $stmt = $link->prepare('SELECT rating FROM rate WHERE p_id =? AND m_id =?');
  16. $stmt->bind_param('ss', $_POST["rating"], $_POST["m_id"]);
  17. // execute query and display results
  18. if (!$stmt->execute()){
  19.         echo "Error executing prepared statement<br />";
  20.         die();
  21.     }
  22.    
  23. if($stmt->fetch()){
  24.     if($DEBUG_MODE)
  25.         echo "[DEBUG]There was a result. Run the update<br />";
  26. }
  27. else{ // no result. Insert it
  28.     if($DEBUG_MODE){
  29.         echo "[DEBUG]There was no result. Insert the rating<br />";
  30.         echo $_SESSION["p_id"].' '.$_POST["m_id"].' '.$_POST["rating"];
  31.         }
  32.  
  33.     $stmt = $link->prepare('INSERT INTO rating (p_id, m_id, rating) VALUES (?, ?, ?)');
  34.     // The following line gives an error of: Call to a member function bind_param() on a non-object
  35.     $stmt->bind_param('sii', $_SESSION["p_id"], $_POST["m_id"], $_POST["rating"] );
  36.     if (!$stmt->execute()){
  37.         echo "Error executing prepared statement<br />";
  38.         echo($link->error);
  39.         echo "<br />".$_SESSION["p_id"];
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment