azdrian 0 Posted June 5, 2011 Report Share Posted June 5, 2011 hello, Going through the example application "my site of quotes" in the book. while testing the application i experience a problem when i add a new quote on the add_quote.php page. the quote is added to the database but this is the error message i got: Fatal error: Cannot redeclare is_administrator() (previously declared in C:\wamp\www\includes\functions.php:7) in C:\wamp\www\includes\functions.php on line 16 here the add_quote page code: <?php // Define a page title and include the header: define('TITLE', 'Add a Quote'); include('templates/header.html'); 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('templates/footer.html'); 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('../mysql_connect.php'); // Prepare the values for storing: $quote = mysql_real_escape_string(trim(strip_tags($_POST['quote'])), $dbc); $source = mysql_real_escape_string(trim(strip_tags($_POST['source'])), $dbc); // Create the "favorite" value: if (isset($_POST['favorite'])) { $favorite = 1; } else { $favorite = 0; } $query = "INSERT INTO quotes (quote, source, favorite) VALUES ('$quote', '$source', $favorite)"; $result = mysql_query($query, $dbc); if (mysql_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 />' . mysql_error($dbc) . '.</p><p>The query being run was: ' . $query . '</p>'; } // Close the connection: mysql_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('templates/header.html'); ?> Quote Link to post Share on other sites
Josee 38 Posted June 5, 2011 Report Share Posted June 5, 2011 Isn't it because you are including the 'header.html' file (from the 'templates' subdirectory) twice, on line 5 and on the last line? 1 Quote Link to post Share on other sites
zanimation 2 Posted June 5, 2011 Report Share Posted June 5, 2011 The example script in the book includes the header on the bottom line but it's just a mistake... you'll need to change it to <?php include('templates/footer.html'); ?> (it makes more sense). 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.