Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'viewing history'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 1 result

  1. Hi Larry, Just want to say thanks for your help in the past. I wasn't really expecting the author to answer questions, lol! I have both the first and second site coded and working (well, except for SSL checkout issue in ex2). However I can't even get the first update in Chapter 12 to ex1 working! Our teacher assigned both chapters 12 and 13 this week for class and I don't see that happening with the problems I'm having getting through just the first part of chapter 12! I personally work better off seeing working code. Do you have a working page.php from chapter 5 (starting on page 130) and one from chapter 12 so I can see the differences? I also noticed the code in the book is different than the database sql and the actual page.php code, which I assume was an update or something? Book code: INSERT INTO history (user_id, type, item_id) VALUES ($user_id, ‘page’, $page_id) page.php code: INSERT INTO history (user_id, type, page_id) VALUES ({$_SESSION['user_id']}, 'page', $page_id) Here is my page.php: <?php // This page displays a specific page of HTML content. // This script is created in Chapter 5. // Require the configuration before any PHP code as the configuration controls error reporting: require('./includes/config.inc.php'); // The config file also starts the session. // Require the database connection: require(MYSQL); $_SESSION['user_id'] =12; $_SESSION['user_not_expired'] = true; // Validate the category ID: if (isset($_GET['id']) && filter_var($_GET['id'], FILTER_VALIDATE_INT, array('min_range' => 1))) { $page_id = $_GET['id']; // Get the page info: $q = 'SELECT title, description, content FROM pages WHERE id=' . $page_id; $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) !== 1) { // Problem! $page_title = 'Error!'; include('./includes/header.html'); echo '<div class="alert alert-danger">This page has been accessed in error.</div>'; include('./includes/footer.html'); exit(); } // Fetch the page info: $row = mysqli_fetch_array($r, MYSQLI_ASSOC); $page_title = $row['title']; include('includes/header.html'); echo '<h1>' . htmlspecialchars($page_title) . '</h1>'; // Display the content if the user's account is current: if (isset($_SESSION['user_not_expired'])) { $user_id = $_SESSION['user_id']; // Bonus material! Referenced in Chapter 12. // Create add to favorites and remove from favorites links: // See if this is favorite: $q = 'SELECT user_id FROM favorite_pages WHERE user_id=' . $user_id . ' AND page_id=' . $page_id; $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) === 1) { echo '<h3 id="favorite_h3"><img src="images/heart_32.png" width="32" height="32"> <span class="label label-info">This is a favorite!</span> <a id="remove_favorite_link" href="remove_from_favorites.php?id=' . $page_id . '"><img src="images/close_32.png" width="32" height="32"></a></h3>'; } else { echo '<h3 id="favorite_h3"><span class="label label-info">Make this a favorite!</span> <a id="add_favorite_link" href="add_to_favorites.php?id=' . $page_id . '"><img src="images/heart_32.png" width="32" height="32"></a></h3>'; } // Show the page content: echo "<div>{$row['content']}</div>"; // Bonus material! Referenced in Chapter 12. // Record this visit to the history table: $q = "INSERT INTO history (user_id, type, page_id) VALUES ({$_SESSION['user_id']}, 'page', $page_id)"; $r = mysqli_query($dbc, $q); // Bonus material! Referenced in Chapter 12. // Allow the user to take notes: // Check for a form submission: if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (isset($_POST['notes']) && !empty($_POST['notes'])) { $notes = $_POST['notes']; $q = "REPLACE INTO notes (user_id, page_id, note) VALUES ($user_id, $page_id, '" . escape_data($notes, $dbc) . "')"; $r = mysqli_query($dbc, $q); if (mysqli_affected_rows($dbc) > 0) { echo '<div class="alert alert-success">Your notes have been saved.</div>'; } } } // Get the existing notes, if any: if (!isset($notes)) { $q = "SELECT note FROM notes WHERE user_id=$user_id AND page_id=$page_id"; $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) === 1) { list($notes) = mysqli_fetch_array($r, MYSQLI_NUM); } } echo '<form id="notes_form" action="page.php?id=' . $page_id . '" method="post" accept-charset="utf-8"> <fieldset><legend>Your Notes</legend> <textarea name="notes" id="notes" class="form-control">'; if (isset($notes) && !empty($notes)) echo htmlspecialchars($notes); echo '</textarea><br> <input type="submit" name="submit_button" value="Save" id="submit_button" class="btn btn-default" /> </fieldset> </form>'; } elseif (isset($_SESSION['user_id'])) { // Logged in but not current. echo '<div class="alert"><h4>Expired Account</h4>Thank you for your interest in this content, but your account is no longer current. Please <a href="renew.php">renew your account</a> in order to view this page in its entirety.</div>'; echo '<div>' . htmlspecialchars($row['description']) . '</div>'; } else { // Not logged in. echo '<div class="alert">Thank you for your interest in this content. You must be logged in as a registered user to view this page in its entirety.</div>'; echo '<div>' . htmlspecialchars($row['description']) . '</div>'; } } else { // No valid ID. $page_title = 'Error!'; include('includes/header.html'); echo '<div class="alert alert-danger">This page has been accessed in error.</div>'; } // End of primary IF. // Add the JavaScript: // Added in Chapter 14. echo '<script type="text/javascript"> var page_id = ' . $page_id . '; </script> <script src="js/favorite.js"></script> <script src="js/notes.js"></script>'; // Include the HTML footer: include('./includes/footer.html'); ?>
×
×
  • Create New...