Jump to content
Larry Ullman's Book Forums

gurroladesign

Members
  • Posts

    1
  • Joined

  • Last visited

Posts posted by gurroladesign

  1. here's my fix...

     

    on the page.php... here's the code you need...

     

    // Bonus material! Referenced in Chapter 5.
    // Rate This Page:
    $q = 'SELECT user_id, rating FROM page_ratings WHERE user_id=' . $_SESSION['user_id'] . ' AND page_id=' . $_GET['id'];
    $r = mysqli_query($dbc, $q);
    $id = $_GET['id'];
      // Fetch the page info:
    $row = mysqli_fetch_array($r, MYSQLI_ASSOC);
    $page_title = $row['rating'];
    if (mysqli_num_rows($r) == 1) {
    echo '<br> <br><div>
    Page Already Rated,  Your Page Rating Is:'.$page_title.'  </div>';
     
     
    else {
    echo ' <br> <br>
    <div>
    Please Rate This Page!
    <form action="rate_this_page.php">
    <select id="rating" name="rating">
          <option value="rating" selected="selected">-- Rate This tutorial--</option>
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          <option value="4">4</option>
          <option value="5">5</option>
          <option value="6">6</option>
          <option value="7">7</option>
          <option value="8">8</option>
          <option value="9">9</option>
          <option value="10">10</option>
      
        </select>
    <input type="hidden" name="id" value="'.$id.'">
     
    <input type="submit"/>
    </form>
    </div>';
    }
     
     
     
    then create the processing page... rate_this_page.php or so...
     
    code you need...
     
    <?php
     
    // This page adds a page of content to the list of the user's favorites.
    // This is bonus material based upon recommendations suggested 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.
     
    // If the user isn't active, redirect them:
    redirect_invalid_user('user_not_expired');
     
    // Require the database connection:
    require(MYSQL);
     
    // Validate the category ID:
    if (filter_var($_GET['id'], FILTER_VALIDATE_INT, array('min_range' => 1))) {
     
     
     
    // Get the page info:
    $q = 'SELECT title, description, content FROM pages WHERE id=' . $_GET['id'];
    $r = mysqli_query($dbc, $q);
    if (mysqli_num_rows($r) != 1) { // Problem!
    $page_title = 'Error!';
    include ('./includes/header.html');
    echo '<p class="error">This page has been accessed in error.</p>';
    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 "<h3>$page_title</h3>";
     
     
     
     
     
     
     
     
    // Add this rating to the database:
    $q = 'REPLACE INTO page_ratings (user_id, page_id, rating) VALUES (' . $_SESSION['user_id'] . ', ' . $_GET['id'] . ','.$_GET['rating'].')';
    $r = mysqli_query($dbc, $q);
    if (mysqli_affected_rows($dbc) == 1) {
    echo '<p>Pge has been rated</p>';
    } else {
    trigger_error('A system error occurred. We apologize for any inconvenience.');
    }
     
     
     
     
     
     
     
     
     
     
    // Show the page content:
    echo "<div>{$row['content']}</div>";
     
    } else { // No valid ID.
    $page_title = 'Error!';
    include ('includes/header.html');
    echo '<p class="error">This page has been accessed in error.</p>';
    } // End of primary IF.
     
    // Include the HTML footer:
    include ('./includes/footer.html');
    ?>
     
     
     
    on the database  itself you might want to insert some test records, optional...
     
    works  on my site...
     
    good luck 
     
×
×
  • Create New...