Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if( !isset($_SESSION["p_id"])){
- echo "Please log in before attempting to rate messages";
- die();
- }
- if( !isset($_POST["m_id"])){
- echo "Invalid message ID";
- die();
- }
- if( !isset($_POST["rating"])){
- echo "Invalid rating";
- die();
- }
- $link = connectDB();
- $stmt = $link->prepare('SELECT rating FROM rate WHERE p_id =? AND m_id =?');
- $stmt->bind_param('ss', $_POST["rating"], $_POST["m_id"]);
- // execute query and display results
- if (!$stmt->execute()){
- echo "Error executing prepared statement<br />";
- die();
- }
- if($stmt->fetch()){
- if($DEBUG_MODE)
- echo "[DEBUG]There was a result. Run the update<br />";
- }
- else{ // no result. Insert it
- if($DEBUG_MODE){
- echo "[DEBUG]There was no result. Insert the rating<br />";
- echo $_SESSION["p_id"].' '.$_POST["m_id"].' '.$_POST["rating"];
- }
- $stmt = $link->prepare('INSERT INTO rating (p_id, m_id, rating) VALUES (?, ?, ?)');
- // The following line gives an error of: Call to a member function bind_param() on a non-object
- $stmt->bind_param('sii', $_SESSION["p_id"], $_POST["m_id"], $_POST["rating"] );
- if (!$stmt->execute()){
- echo "Error executing prepared statement<br />";
- echo($link->error);
- echo "<br />".$_SESSION["p_id"];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment