khassan Posted December 17, 2018 Share Posted December 17, 2018 Not sure why I keep getting this error? Could someone please help me. This is the code I used for add_quote.php: <?php // Script 13.7 - add_quote.php /* This script adds a quote. */ // Define a page title and include the header: define('TITLE', 'Add a Quote'); include('includes/header.php'); print '<h2>Add 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('includes/footer.php'); exit(); } // Check for a form submission: if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Handle the form. if ( !empty($_POST['quote']) && !empty($_POST['source']) ) { // Need the database connection: include('includes/mysqli_connect.php'); // 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; } $query = "INSERT INTO quotes (quote, source, favorite) VALUES ('$quote', '$source', $favorite)"; mysqli_query($dbc, $query); if (mysqli_affected_rows($dbc) == 1){ // Print a message: print '<p>Your quotation has been stored.</p>'; } else { print '<p class="error">Could not store the quote because:<br>' . mysqli_error($dbc) . '.</p><p>The query being run was: ' . $query . '</p>'; } // Close the connection: mysqli_close($dbc); } else { // Failed to enter a quotation. print '<p class="error">Please enter a quotation and a source!</p>'; } } // End of submitted IF. // Leave PHP and display the form: ?> <form action="add_quote.php" method="post"> <p><label>Quote <textarea name="quote" rows="5" cols="30"></textarea></label></p> <p><label>Source <input type="text" name="source"></label></p> <p><label>Is this a favorite? <input type="checkbox" name="favorite" value="yes"></label></p> <p><input type="submit" name="submit" value="Add This Quote!"></p> </form> <?php include('includes/footer.php'); ?> And then the one for functions.php: <?php // Script 13.2 - functions.php /* This page defines custom functions. */ // This function checks if the user is an administrator. // This function takes two optional values. // This function returns a Boolean value. function is_administrator($name = 'Samuel', $value = 'Clemens') { // Check for the cookie and check its value: if (isset($_COOKIE[$name]) && ($_COOKIE[$name] == $value)) { return true; } else { return false; } } // End of is_administrator() function. Could someone please also explain the fact that we had to use Samuel for the $name and Clemens for the $value? I am so confused... I'd really appreciate any clarification! =] Link to comment Share on other sites More sharing options...
khassan Posted December 17, 2018 Author Share Posted December 17, 2018 I was able to solve this! I went through my code again and I had the include function commented out on one of my files >.< Sorry, guys. Thank you. Link to comment Share on other sites More sharing options...
Larry Posted December 17, 2018 Share Posted December 17, 2018 Awesome. Kudos for figuring it out and thanks for letting us know! Link to comment Share on other sites More sharing options...
Recommended Posts