function showBookDetails($connection, $isbn) { $query = "SELECT * FROM books NATURAL JOIN inventory WHERE isbn = '{$isbn}';"; $results = mysql_query($query, $connection); if (!$results) { die('Could not get search result: ' . mysql_error()); } $num_rows = mysql_num_rows($results); if ($num_rows == 0) { echo "<p class='center'>Sorry, book with ISBN {$isbn} is not found. </p>"; return; } $row = mysql_fetch_assoc($results); $price_string = money_format("%i", $row['price']); echo "\n <table>\n <tr>\n <th class='right'>ISBN</th>\n <td>{$row['isbn']}</td>\n <td class='image' rowspan='6'>\n <img src='show_image.php?isbn={$isbn}' alt='Book Cover Image' height='240'>\n </td>\n </tr>\n <tr>\n <th class='right'>Title</th>\n <td class='strong'>{$row['title']}</td>\n </tr>\n <tr>\n <th class='right'>Author</th>\n <td>{$row['author']}</td>\n </tr>\n <tr>\n <th class='right'>Publisher</th>\n <td>{$row['publisher']}</td>\n </tr>\n <tr>\n <th class='right'>Price</th>\n <td>\${$price_string}</td>\n </tr>\n <tr>\n <th class='right'>Quantity</th>\n <td>{$row['quantity']}</td>\n </tr>\n </table>\n <br>"; $books = $_COOKIE['books']; $isbn = $row['isbn']; if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (insertReview($connection, $isbn)) { return; } } showAddReviewForm($connection, $isbn); }
function addReview($complexID, $review, $email) { $reviewID = insertReview($review); $userID = getUserId($email); $db = dbConnection(); try { $sql = 'INSERT INTO complexReview(complex_id, review_id, user_id) VALUES(:complexID, :reviewID, :userID)'; $stmt = $db->prepare($sql); $stmt->bindValue(':complexID', $complexID, PDO::PARAM_INT); $stmt->bindValue(':reviewID', $reviewID, PDO::PARAM_INT); $stmt->bindValue(':userID', $userID['user_id'], PDO::PARAM_INT); $result = $stmt->execute(); $stmt->closeCursor(); } catch (PDOException $e) { echo $message = "PDO Failure"; } if ($result) { return TRUE; } else { return FALSE; } }
$game["game_id"] = $app->lastInsertId(); // echo "<!-- game_id: " . $game["game_id"] . " -->"; } $review["game_id"] = $game["game_id"]; // echo "<!-- Update like status for the game. -->\n"; if ($review["like"] == "yes") { $game["like_it"] += 1; } else { $game["not_like_it"] += 1; } updateGame($game); require 'model/reviews.php'; // echo "<!-- Insert the new review in the database. -->\n"; // echo "<!-- game_id: " . $review["game_id"] . " -->\n"; // echo "<!-- audience_id: " . $review["audience_id"] . " -->\n"; insertReview($review); // echo "<!-- Get the ID of the newly inserted review. -->\n"; $review["review_id"] = $app->lastInsertId(); require 'model/comments.php'; // echo "<!-- Insert the different comments into the database. -->\n"; if ($review["why_like"] != NULL) { $comments["why"]["genre_id"] = NULL; $comments["why"]["review_id"] = NULL; $comments["why"]["feature_id"] = NULL; $comments["why"]["game_id"] = $review["game_id"]; $comments["why"]["content"] = $review["why_like"]; $comments["why"]["review_id"] = $review["review_id"]; } if ($review["strengths"] != NULL) { $comments["strengths"]["genre_id"] = NULL; $comments["strengths"]["review_id"] = NULL;