Jump to content
Larry Ullman's Book Forums

Alex1

Members
  • Posts

    2
  • Joined

  • Last visited

Posts posted by Alex1

  1. I have been getting some errors in my chapter 13 site and I am not sure how I can fix them. I am able to login with the login.php page.

    When I do I get this error.

    ?php // Script 13.4 - footer.html // Display general admin links... // - if the user is an administrator and it's not the logout.php page // - or if the $loggedin variable is true (i.e., the user just logged in) if ( (is_administrator() && (basename($_SERVER['PHP_SELF']) != 'logout.php')) OR (isset($loggedin) && $loggedin) ) { // Create the links: print '

     

    When I go to the add_quotes.php page I get this error.
     

    Quote

     

    Warning: include(../mysqli_connect.php): failed to open stream: No such file or directory in C:\xampp\htdocs\PHP\Chapter 13\view_quotes.php on line 18

    Warning: include(): Failed opening '../mysqli_connect.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\PHP\Chapter 13\view_quotes.php on line 18
    Notice: Undefined variable: dbc in C:\xampp\htdocs\PHP\Chapter 13\view_quotes.php on line 24


    Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\PHP\Chapter 13\view_quotes.php on line 24


    Notice: Undefined variable: dbc in C:\xampp\htdocs\PHP\Chapter 13\view_quotes.php on line 44


    Warning: mysqli_error() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\PHP\Chapter 13\view_quotes.php on line 44

    Could not retrieve the data because:

    The query being run was: SELECT id, quote, source, favorite FROM quotes ORDER BY date_entered DESC
    Notice: Undefined variable: dbc in C:\xampp\htdocs\PHP\Chapter 13\view_quotes.php on line 47
    Warning: mysqli_close() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\PHP\Chapter 13\view_quotes.php on line 47
    ?php // Script 13.4 - footer.html // Display general admin links... // - if the user is an administrator and it's not the logout.php page // - or if the $loggedin variable is true (i.e., the user just logged in) if ( (is_administrator() && (basename($_SERVER['PHP_SELF']) != 'logout.php')) OR (isset($loggedin) && $loggedin) ) { // Create the links: print '

     

     

    When I try and add a quote I get this list of errors.

     

    Quote

     

    Warning: include(C:/xampp/htdocs/PHP/Chapter13/mysqli_connect.php): failed to open stream: No such file or directory in C:\xampp\htdocs\PHP\Chapter 13\add_quote.php on line 23

    Warning: include(): Failed opening 'C:/xampp/htdocs/PHP/Chapter13/mysqli_connect.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\PHP\Chapter 13\add_quote.php on line 23

    Notice: Undefined variable: dbc in C:\xampp\htdocs\PHP\Chapter 13\add_quote.php on line 26

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\PHP\Chapter 13\add_quote.php on line 26

    Notice: Undefined variable: dbc in C:\xampp\htdocs\PHP\Chapter 13\add_quote.php on line 27

    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\PHP\Chapter 13\add_quote.php on line 27

    Notice: Undefined variable: dbc in C:\xampp\htdocs\PHP\Chapter 13\add_quote.php on line 37

    Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\PHP\Chapter 13\add_quote.php on line 37

    Notice: Undefined variable: dbc in C:\xampp\htdocs\PHP\Chapter 13\add_quote.php on line 39

    Warning: mysqli_affected_rows() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\PHP\Chapter 13\add_quote.php on line 39

    Notice: Undefined variable: dbc in C:\xampp\htdocs\PHP\Chapter 13\add_quote.php on line 43

    Warning: mysqli_error() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\PHP\Chapter 13\add_quote.php on line 43

    Could not store the quote because:
    .

    The query being run was: INSERT INTO quotes (quote, source, favorite) VALUES ('', '', 1)


    Notice: Undefined variable: dbc in C:\xampp\htdocs\PHP\Chapter 13\add_quote.php on line 47

    Warning: mysqli_close() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\PHP\Chapter 13\add_quote.php on line 47

     

     

     

    Here is my add_quotes.php code

    I am getting a red underline error on the  ! is administrator line

    I added LINE is # where each line error is for my error list above

    <?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('templates/header.html');
    
    print '<h2>Add a Quotation</h2>';
    
    // Restrict access to administrators only:
    if (!is_administrator()) { (THIS LINE IS GIVING ME AN ERROR)
    	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:
    	LINE 23	include('C:/xampp/htdocs/PHP/Chapter13/mysqli_connect.php');
    
    		// Prepare the values for storing:
    	LINE 26	$quote = mysqli_real_escape_string($dbc, trim(strip_tags($_POST['quote'])));
    	LINE 27	$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)";
    		LINE 37 mysqli_query($dbc, $query);
    
    		LINE 39 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:
    		LINE 47 mysqli_close($dbc);
    
    	} else { // Failed to enter a quotation.
    	LINE 43	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/footer.html'); ?>

     

     

     

     

  2. This is sort of long.

     

    Chapter 12

    I am going through chapter 12 in the Quick Start Guide PHP for the Web and am having an issue creating the myblog database on PHPMyAdmin from Installation and Configuration A. I have created the database in PHPMyAdmin with the database button. This gives me the option to make a table and columns. I am not sure where I am supposed to put the text:

    1125577696_Screenshot(109)_LI.thumb.jpg.e9305b21cbfe9b3f28858c5df9e1f8a1.jpg

    I am not sure where this is supposed to go on PHPMyAdmin in order to make the database. The book doesn't explain where it is supposed to go.

     

    929968456_Screenshot(108).thumb.png.29cad3153a89f5c52c02b8522100904a.png

     

    When I try and connect to mysql I get the error:

    Quote

     

    Warning: mysqli_connect(): (HY000/1045): Access denied for user 'username'@'localhost' (using password: YES)

    Could not connect to the database

     

    I am guessing that this is because I have not been able to make the database, and that it might go away after I make it.

    I am using Mysql Workbench which seems as well as XAMPP. The server status is able to run but it is not able to connect. The user is root

    I am also having other errors with the other pages, such as Edit an Entry

    Quote

     

    Warning: mysqli_connect(): (HY000/1045): Access denied for user 'username'@'localhost' (using password: YES) in C:\xampp\htdocs\PHP\Chapter 12\edit_entry.php on line 13

    Warning: mysqli_set_charset() expects parameter 1 to be mysqli, bool given in C:\xampp\htdocs\PHP\Chapter 12\edit_entry.php on line 16

    This page has been accessed in error.
    Warning: mysqli_close() expects parameter 1 to be mysqli, bool given in C:\xampp\htdocs\PHP\Chapter 12\edit_entry.php on line 72

     

    This will probably be fixed after I am able to connect to Mysql.

    Chapter 13

    The page titled My Site of Quotes does not work because I am getting a lot of errors.

     

    1260990203_Screenshot(111).thumb.png.3c1e7e498934ad4271925bed85258560.png

     

    This might be because I have not gotten Mysql to run yet, and it might be fixed after. The other pages have similar issues.

     

    I also wanted to check to make sure that I have the files set up correctly.

    Here is what it is supposed to look like:

    Image

     

    Here are how my files are set up

     

    1937064317_Screenshot(112).thumb.png.e8a9d735c22f4bf1e1d83e0489948724.png

×
×
  • Create New...