khassan Posted December 17, 2018 Share Posted December 17, 2018 Greetings! I am having this issue (screenshot attached). I am able to add quotes to the database and see them in the database when logging in to phpMyAdmin, but for some reason I am getting this error on the View Quotes page: All Quotes Could not retrieve the data because: Unknown column 'id' in 'field list'. The query being run was: SELECT id, quote, source, favorite FROM quotes ORDER BY date_entered DESC Is there a reason for this? This is the code that I am using for the View All Quotes page: <?php // Script 13.8 - view_quotes.php /* This script lists every quote. */ // Include the header: define('TITLE', 'View All Quotes'); include('includes/header.php'); print '<h2>All Quotes</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('includes/footer.php'); exit(); } // Need the database connection: include('includes/mysqli_connect.php'); // Define the query: $query = 'SELECT id, quote, source, favorite FROM quotes ORDER BY date_entered DESC'; // Run the query: if ($result = mysqli_query($dbc, $query)) { // Retireve the returned records: while ($row == mysqli_fetch_array($result)) { // Print the record: print "<div><blockquote>{$row['quote']}</blockquote>- {$row['source']}\n"; // Is this a favorite? if ($row['favorite'] == 1) { print ' <strong>Favorite!</strong>'; } // Add administrative links: print "<p><b>Quote Admin:</b> <a href=\"edit_quote.php?id={$row['id']}\">Edit</a> <-> <a href=\"delete_quote.php?id={$row['id']}\">Delete</a></p></div>\n"; } // End of while loop. } else { // Query didn't run. print '<p class="error">Could not retrieve the data because:<br>' . mysqli_error($dbc) . '.</p><p>The query being run was: ' . $query . '</p>'; } // End of query IF. mysqli_close($dbc); // Close the connection. include('includes/footer.php'); // Include the footer. ?> I also attached a screenshot of my file directory, and of the added quotes on phpmyadmin site, not sure if that helps. As far as the folder being named "includes" instead of "templates," that was the Professor's call. She wanted us to name that folder that way. Any clarification will be greatly appreciated! Link to comment Share on other sites More sharing options...
Larry Posted December 17, 2018 Share Posted December 17, 2018 Apologies if this is due to a book error, but your query uses "id" while the database table uses "quote_id". Link to comment Share on other sites More sharing options...
Recommended Posts