Jump to content
Larry Ullman's Book Forums


  • Posts

  • Joined

  • Last visited

Everything posted by guvna

  1. I'm aware why I'm getting the warning. Do you mean change my entire website as every page includes the header file and will therefore echo the page title. For example remove the echo and hard code the <html> <title> tag? If there is an example of how such as page should be structured I would be grateful for direction.
  2. In chapter 3.2 the code was introduced: <title><?php echo $page_title; ?></title> Having now contructed a website based on this I'm having error now using the header() function such as redirecting and form submission. Each page includes the header file and defines the page title: // include the header file: include ('../includes/my_header.inc.php'); // Create the page title: $page_title = 'My Page Title'; //line #13 Whenever I use the header() now I get this error: Warning: Cannot modify header information - headers already sent by (output started at /home/mydomain/public_html/includes/my_header.inc.php:13) Is there a way round this or do I have to redesign the website?
  3. Placing this in 4th Edition as that's the book I'm working through. I've created a form with three inputs (Agent, Guest, Email) but Agent is not required. I'm trying to display different messages whether Agent is input or not but cannot get that part to work. I know the reset button doesn't work but that's just as the form was copied from an old html page. I'll get into field content validation once I can get past this stage as I have multiple fields to add but need to display different messages on form submission dependent on which fields get completed. <!DOCTYPE HTML> <html> <head> <meta http-equiv="content-type" content="text/html" charset="utf-8"> <title>frm_request_home</title> </head> <body> <?php // Start input validation: // Validate the Agent: if (!empty($_POST['agent'])) { $agent = $_POST['agent']; } else { $agent = NULL; } // Validate the Guest Name: if (!empty($_POST['guest'])) { $guest = $_POST['guest']; } else { $guest = NULL; echo '<p class="error"> You forgot to enter the guest name!</p>'; } // Validate the Email Address: if (!empty($_POST['email'])) { $email = $_POST['email']; } else { $guest = NULL; echo '<p class="error"> You forgot to enter your email address!</p>'; } // Conditional to check for form submission: if ($_SERVER['REQUEST_METHOD'] == 'POST') { // form validation: if (!isset($_POST['agent']) ) { // Print the results if Agent: echo "<p>Thank you <b>$agent</b> for your request for <b>$guest</b>.</p> <p>We will reply to you at <i>$email</i>.</p>\n"; // Print the results if Guest: } elseif (!empty($_POST['guest']) && !empty($_POST['email']) ) { echo "<p>Thank you, <b>$guest</b>, for your request.</p> <p>We will reply to you at <i>$email</i>.</p>\n"; } else { // missing form value. echo '<p class"error"> Please fill out the form again.</p>'; } } // Leave the PHP section and create the HTML form: ?> <table width="98%" border="0" align="center" cellpadding="2" cellspacing="0" class="tblBorder"> <tr> <td align="center" class="txtHeaderRev">Request Form</td> </tr> <tr> <td> <form action="frm_request_home.php" method="post"> <table width="86%" border="0" align="center" cellpadding="3" cellspacing="0"> <tr> <td align="right" class="txtMain">Agency Name (if applicable):</td> <td><input type="text" name="agent" value="<?php if (isset($_POST['agent'])) echo $_POST['agent']; ?>" style="width:250px;" /></td> </tr> <tr> <td width="46%" align="right" class="txtMain">Guest Name :</td> <td><input type="text" name="guest" value="<?php if (isset($_POST['guest'])) echo $_POST['guest']; ?>" style="width:250px;" /></td> </tr> <tr> <td align="right" class="txtMain">Email Address:</td> <td><input type="text" name="email" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" style="width:250px;" /></td> </tr> <tr> <td>&nbsp;</td> <td> <input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /> </td> </tr> <tr> <td>&nbsp;</td> <td>&nbsp;</td> </tr> </table> </form> </td> </tr> </table> </body> </html>
  4. Need some directions with this question please: in login.php we have: // Assign $data to $errors for login_page.inc.php: $errors = $data; and in login_page.inc.php we have: // Print any error messages , if they exist: if (isset($errors) && !empty($errors)) { echo '<h1>Error!</h1> <p class="error">The following error(s) occurred:<br />'; foreach ($errors as $msg) { echo " - $msg<br />\n"; } // End of foreach. echo '<\p><p>Please try again.</p>'; // First closing <\p> tag displays in browser or error! } // End of errors IF. btw: I get '</p>' displayed on screen with this code along with errors (script 12#1). I need some direction on whether to change login.php to handle each error, to edit login_page_inc.php or both? I tried editing login_page_inc.php but the errors (if there are any) clear too quickly and the redirect script sends me to the home page. I will continue the book but would like to come back and address this.
  5. Larry, 'guilty as charged'. User error. Script 12.7 line 20: if ( (isset I had: if ( (!isset and only realized when I changed the script in 12.10. Humble apologies.
  6. There is a similar posting but they don't have id's so that was the topic title 'Chap 12 - 12.6 Example' which doesn't look like it was resolved. Due to the advances in web browsers I can't review the cookies as per the example K on page 387. First of all, on script 12.7, there seems to be a typo on line 3: <head"> (the double quotation mark). When I first load index.php the header.html displays Logout which seems strange as I haven't logged in yet. Selecting Logout takes me back to index.php and the header.html is still displaying Logout. When I load login.php directly I can login and the browser displays 'first_name' and the logout button below. However, when logged in, the header is displaying Login. I can select logout below 'first_name' and am logged out with the logout.php script but the header still displays Login. I have tested in Firefox and Chrome with the same results. I have checked the scripts character ny character. Apache Version: 2.4.23 PHP Version: 5.6.25 Firefox: 58.0.2 (64-bit) Chrome: Version 64.0.3282.186 (Official Build) (64-bit)
  7. Script 10#4 works for pagination, in my case 6 pages. Script 10#5 sort on First Name and Last Name work on the initial page display after selected column heading but not for selecting pages after the sort selection. My url shows view_users_3.php as I save each iteration of the scripts to review. Viewing my page then selecting sort by last name shows: url = view_users_3.php?sort=ln The first page of results displays correctly by last name. selecting the page 2: url = view_users_3.php?s=10&p=6&sortln The second page of results is showing user_id's 10 to 19 so has not sorted by last_name. The same situation occurs when I use First Name and Date Registered. I rechecked the code and noted lines 68-70 with the href tags (also from forum Sep 2013) not highlighted but cannot find any other difference with my code. My code: <?php # Chapter 10: Script 10.5: view_users_3.php //This script retrievs all the records from the users table. //This 10.5 version allows results to be sorted in different ways. $page_title = 'View the Current Users'; include ('../includes/header.html'); echo '<h1>Registered Users</h1>'; // Page header require_once ('../includes/mysqli_connect.php'); // Connect to the db. // Number of records to show per page. $display = 10; // Determine how many pages there are ... if (isset($_GET['p']) && is_numeric ($_GET['p'])) { // Already been determined. $pages = $_GET['p']; } else { // Need to determine. // Count the number of records. $q = "SELECT COUNT(user_id) FROM users"; $r = @mysqli_query ($dbc, $q); $row = @mysqli_fetch_array ($r, MYSQLI_NUM); $records = $row[0]; // Calcualte the number of pages... if ($records > $display) { // More than 1 page. $pages = ceil ($records/$display); } else { $pages = 1; } } // End of p IF. // Determine where in the database to start returning results... if (isset($_GET['s']) && is_numeric ($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } // Determine the sort... // Default is by registration date. $sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'rd'; // Determine the sorting order. switch ($sort) { case 'ln': $order_by = 'last_name ASC'; break; case 'fn': $order_by = 'first_name ASC'; break; case 'rd': $order_by = 'registration_date ASC'; break; default: $order_by = 'registration_date ASC'; $sort = 'rd'; break; } // Define the query: $q = "SELECT last_name, first_name, DATE_FORMAT(registration_date, '%M %d, %Y') AS dr, user_id FROM users ORDER BY $order_by LIMIT $start, $display"; $r = @mysqli_query ($dbc, $q); // run the query. // Table header. echo '<table align="center" cellspacing="3" cellpadding="3" width="75%"> <tr> <td align="left"><b>Edit</b></td> <td align="left"><b>Delete</b></td> <td align="left"><b><a href="view_users_3.php?sort=ln">Last Name</a></b></td> <td align="left"><b><a href="view_users_3.php?sort=fn">First Name</a></b></td> <td align="left"><b><a href="view_users_3.php?sort=rd">Date Registered</a></b></td> </tr> '; // Fetch and print all the records. $bg = '#eeeeee'; // Set the initial background color. while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color. echo '<tr bgcolor="' . $bg . '"> <td align="left"><a href="edit_user.php?id=' . $row['user_id'] . '">Edit</a></td> <td align="left"><a href="delete_user.php?id=' . $row['user_id'] . '">Delete</a></td> <td align="left">' . $row['last_name'] . '</td> <td align="left">' . $row['first_name'] . '</td> <td align="left">' . $row['dr'] . '</td> </tr> '; } // End of WHILE loop. echo '</table>'; //Close the table. mysqli_free_result ($r); // Free up the resources. mysqli_close($dbc); // Close the database connection. // Make the links to other pages, if necessary. if ($pages > 1) { echo '<br /><p>'; // Add some spacing and start a paragraph. $current_page = ($start/$display) + 1; // Determine what page the script is on. // If it's not the first page, make a previous link: if ($current_page != 1) { echo '<a href="view_users_3.php?s=' . ($start - $display) . '&p=' . $pages . '&sort=' . $sort . '">Previous</a> '; } // Make all the numbered pages. for ($i = 1; $i <= $pages; $i++) { if ($i != $current_page) { echo '<a href="view_users_3.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '&sort' . $sort . '">' . $i . '</a> '; } else { echo $i . ' '; } } // End of FOR loop. // If it's not the last page, make a Next button. if ($current_page != $pages) { echo '<a href="view_users_3.php?s=' . ($start + $display) . '&p=' . $pages . '&sort' . $sort . '">Next</a>'; } echo '</p>'; // Close the paragraph. } // End of links section. include ('../includes/footer.html'); ?>
  8. it might be a MySQL Workbench thing as I can right click the BLOB icon then left click 'open in viewer' then see the result '1234' in the text tab.
  9. Scripts 1, 2 and 3 from page 238 all work fine. When I run script 4 on page 239 and run: SELECT 8 FROM customers WHERE customer_id=1; the table displays 'BLOB' in the pin field rather than the expected '1234'. I did look up BLOB erros and my character set is definately utf8 with collation utf8 general ci.
  10. I've shown the error to a friend who works with Microsoft SQL and he suggests the syntax in the book is missing some elements. Below is code that he suggested to try and it works. MAX is just an example to show the code working: SELECT MAX(f.name), COALESCE(MAX(m.date_entered), 'N/A') AS last_post FROM forums AS f LEFT JOIN messages AS m USING (forum_id) GROUP BY (m.forum_id) ORDER BY MAX(m.date_entered) DESC;
  11. OK so the alias AS I get. The m.messages relates to the table for the 'AS m' part. The fact that you use m for messages table, f for forum table could just as easily be x and y?
  12. Page 220 syntax: SELECT f.name, COALESCE(MAX(m.date_entered), 'N/A') AS last_post FROM forums AS f -- my tablename is 'forums'. LEFT JOIN messages AS m USING (forum_id) GROUP BY (m.forum_id) ORDER BY m.date_entered DESC; Results in this error: #1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'rich_forum.f.name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
  13. Up to this point in the book all references to tables and fieldnames have been spelt out in full. In this chapter the examples introduce a new format for the syntax: SELECT m.message_id, m.subject, f.name etc Whilst the code works as described I cannot find any description for the preceding character and period syntax or choice of character. An explanation would be very useful for me to better understand this process if anyone could provide it please.
  • Create New...