Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'chapter 13 edit_quotes.php de'.

  • 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. I'm working with the last chapter in book trying to put it all together but, the edit quotes.php and delete quotes.php, gives me this error below. "This page has been accessed in error." I made sure that I'm logged in using the me@example.com and testpass password and even checked my scripts with yours I think everything lined up. Can you please help? Edit_quotes.php Script <?php // Script 13.9 - edit_quote.php /* This script edits a quote. */ // Define a page title and include the header: define('TITLE', 'Edit a Quote'); include('templates/header.html'); print '<h2>Edit a Quotation</h2>'; // Restrict access to administators only: if (!is_administrator()) { print '<h2>Access Denied!</h2><p class="error">You do not have permission to access this page.</p>'; include('templates/footer.html'); exit(); } // Need the database connection: include('../mysqli_connect.php'); if (isset($_GET['id']) && is_numeric($_GET['id']) && ($_GET['id'] > 0) ) { // Display the entry in a form: // Define the query. $query = "SELECT quote, source, favorite FROM quotes WHERE id={$_GET['id']}"; if ($result = mysqli_query($dbc, $query)) { // Run the query. $row = mysqli_fetch_array($result); // Retrieve the information. // Make the form: print '<form action="edit_quote.php" method="post"> <p><label>Quote <textarea name="quote" rows="5" cols="30">' . htmlentities($row['quote']) . '</textarea></label></p> <p><label>Source <input type="text" name="source"value="' . htmlentities($row['source']) . '"></label></p> <p><label>Is this a favorite? <input type="checkbox" name="favorite" value="yes"'; // Check the box if it is a favorite: if ($row['favorite'] == 1) { print ' checked="checked"'; } // Complete the form: print '></label></p> <input type="hidden" name="id" value="' . $_GET['id'] . '"> <p><input type="submit" name="submit" value="Update This Quote!"></p> </form>'; } else { // Couldn't get the information. print '<p class="error">Could not retrieve the quotation because:<br>' . mysqli_error($dbc) . '.</p><p>The query being run was: ' . $query . '</p>'; } } elseif (isset($_POST['id']) && is_numeric($_POST['id']) && ($_POST['id'] > 0)) { // Handle the form. // Validate and secure the form data: $problem = FALSE; if ( !empty($_POST['quote']) && !empty($_POST['source']) ) { // Prepare the values for storing: $quote = mysqli_real_escape_string($dbc, trim(strip_tags($_POST['quote']))); $source = mysqli_real_escape_string($dbc, trim(strip_tags($_POST['source']))); // Create the "favorite" value: if (isset($_POST['favorite'])) { $favorite = 1; } else { $favorite = 0; } } else { print '<p class="error">Please submit both a quotation and a source.</p>'; $problem = TRUE; } if (!$problem) { // Define the query. $query = "UPDATE quotes SET quote='$quote', source='$source', favorite=$favorite WHERE id={$_POST['id']}"; if ($result = mysqli_query($dbc, $query)) { print '<p>The quotation has been updated.</p>'; } else { print '<p class="error">Could not update the quotation because:<br>' . mysqli_error($dbc) . '.</p><p>The query being run was: ' . $query . '</p>'; } } // No problem! } else { // No ID set. print '<p class="error">This page has been accessed in error.</p>'; } // End of main IF. mysqli_close($dbc); // Close the connection. include('templates/footer.html'); // Include the footer. ?> Delete_quotes.php Script <?php // Script 13.10 - delete_quote.php /* This script deletes a quote. */ // Define a page title and include the header: define('TITLE', 'Delete a Quote'); include('templates/header.html'); print '<h2>Delete a Quotation</h2>'; // Restrict access to administrators only: if (!is_administrator()) { print '<h2>Access Denied!</h2><p class="error">You do not have permission to access this page.</p>'; include('templates/footer.html'); exit(); } // Need the database connection: include('../mysqli_connect.php'); if (isset($_GET['id']) && is_numeric($_GET['id']) && ($_GET['id'] > 0) ) { // Display the quote in a form: // Define the query: $query = "SELECT quote, source, favorite FROM quotes WHERE id={$_GET['id']}"; if ($result = mysqli_query($dbc, $query)) { // Run the query. $row = mysqli_fetch_array($result); // Retrieve the information. // Make the form: print '<form action="delete_quote.php" method="post"> <p>Are you sure you want to delete this quote?</p> <div><blockquote>' . $row['quote'] . '</blockquote>- ' . $row['source']; // Is this a favorite? if ($row['favorite'] == 1) { print ' <strong>Favorite!</strong>'; } print '</div><br><input type="hidden" name="id" value="' . $_GET['id'] . '"> <p><input type="submit" name="submit" value="Delete this Quote!"></p> </form>'; } else { // Couldn't get the information. print '<p class="error">Could not retrieve the quote because:<br>' . mysqli_error($dbc) . '.</p><p>The query being run was: ' . $query . '</p>'; } } elseif (isset($_POST['id']) && is_numeric($_POST['id']) && ($_POST['id'] > 0) ) { // Handle the form. // Define the query: $query = "DELETE FROM quotes WHERE id={$_POST['id']} LIMIT 1"; $result = mysqli_query($dbc, $query); // Execute the query. // Report on the result: if (mysqli_affected_rows($dbc) == 1) { print '<p>The quote entry has been deleted.</p>'; } else { print '<p class="error">Could not delete the blog entry because:<br>' . mysqli_error($dbc) . '.</p><p>The query being run was: ' . $query . '</p>'; } } else { // No ID received. print '<p class="error">This page has been accessed in error.</p>'; } // End of main IF. mysqli_close($dbc); // Close the connection. include('templates/footer.html'); ?>
×
×
  • Create New...