Jump to content
Larry Ullman's Book Forums

Jacques

Members
  • Posts

    75
  • Joined

  • Last visited

Everything posted by Jacques

  1. I have now also included config.inc and MYSQL function, although they are also included in the header as previously mentioned. I still get the following error: An error occurred in script 'C:\xampp\htdocs\site\includes\form_functions.inc.php' on line 75: Undefined variable: dbc Below the revised code: } elseif ($name == 'timezone') { // Create a list of time zones. // Retrieve the timezones. require_once ('includes/config.inc.php'); require_once (MYSQL); $q = "SELECT timezone_id, timezone FROM timezones ORDER BY timezone ASC"; $r = mysqli_query ($dbc, $q); while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) { echo "<option value=\"$row[0]\""; } $data = $r; // Free the results: mysqli_free_result($r);
  2. Hi Larry, Thank your for your continued advice. As I am still very new at web development I get lost very easy. What do you mean by "that the value will depend upon the value of the checkbox"? Do I have to change the value from "True" to "Yes"? I have started a new thread for my second question. Kind regards, Jacques
  3. I want to add select menus to the registration form within the form_functions script, using data retrieved from the database instead of hard coding them. I tried the code included below after l looked at the form_function script for the coffee site, but get the following errors: Warning: print_r() [function.print-r]: Couldn't fetch mysqli_result in C:\xampp\htdocs\site\includes\config.inc.php on line 69 Warning: print_r() [function.print-r]: Property access is not allowed yet in C:\xampp\htdocs\site\includes\config.inc.php on line 69 The "require Config and MySQL" are contained in the header. } elseif ($type == 'select') { // Create a select menu. if (($name == 'timezone')) { // Create a list of timezones. // Retrieve the timezones. $q = "SELECT timezone_id, timezone FROM timezones ORDER BY timezone ASC"; $r = mysqli_query ($dbc, $q); while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) { echo "<option value=\"$row[0]\""; } $data = $r; // Free the results: mysqli_free_result($r); Thank you in advance.
  4. Thank you for the response Larry and Margaux. I have managed to get the checkbox to work but just need confirmation from you on the "quality" of the code. form_functions script: } elseif ($type == 'checkbox') { // Create a checkbox. // Start creating the input: echo '<input type="' . $type . '" name="' . $name . '" id="' . $name . '"'; // Add the value to the input: if ($value == TRUE) echo 'checked="checked"'; // Check for an error: if (array_key_exists($name, $errors)) { echo 'class="error" /> <span class="error">' . $errors[$name] . '</span>'; } else { echo ' />'; } register script: // Validate the terms: if (isset($_POST['terms'])) { $t = TRUE; } else { $reg_errors['terms'] = 'You must accept the terms and conditions of use.'; } register script form: <p><label for="terms"></label><?php create_form_input('terms', 'checkbox', $reg_errors); ?> <small>I have read, understood and agree to the <a href="terms.php" title="View Terms and Conditions">terms and conditions</a> of use.</small></p> I also want to use data retrieved from the database for select menus in the form_functions script. The "require Config and MySQL" are contained in the header. I however get the following errors: Warning: print_r() [function.print-r]: Couldn't fetch mysqli_result in C:\xampp\htdocs\site\includes\config.inc.php on line 69 Warning: print_r() [function.print-r]: Property access is not allowed yet in C:\xampp\htdocs\site\includes\config.inc.php on line 69 The code is as follows: } elseif ($type == 'select') { // Create a select menu. if (($name == 'timezone')) { // Create a list of timezones. // Retrieve the timezones. $q = "SELECT timezone_id, timezone FROM timezones ORDER BY timezone ASC"; $r = mysqli_query ($dbc, $q); while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) { echo "<option value=\"$row[0]\""; } $data = $r; // Free the results: mysqli_free_result($r); Thank you in advance.
  5. I have added an "Accept Terms" check box to the registration form. It seems to work with the exception that it has no stickiness. Any help will be appreciated. Below my code snippets: form_functions.inc.php // Conditional to determine what kind of element to create: if ( ($type == 'text') || ($type == 'password') || ($type == 'checkbox') ) { // Create text or password or checkbox inputs. register.php - validation: // Validate the terms: if (isset($_POST['terms'])) { $t = TRUE; } else { // Terms not checked. $reg_errors['terms'] = 'You must accept the terms and conditions of use.'; } register.php - form <p><label for="terms"></label><?php create_form_input('terms', 'checkbox', $reg_errors); if (isset($_POST['terms']) && $_POST['terms'] == "Yes") echo "checked"; ?> <small>I have read and agree to the <a href="terms.php" title="View Terms and Conditions">terms and conditions</a> of use.</small></p> Thank you in advance.
  6. Hi Larry. Thank you for your reply. I realised that my questions had been inarticulate as I think your reply refers to displaying for example a username once a user is logged in, if I understand it correctly? What I meant to ask was: How do I get the activation script to pass on the user's email address to the email address field (autofill) in the login form when the user activates his or her account, simular to when a user register for the site or reset his or her password? The user then only has to enter his or her password to log in. It is for consistancy purposes. Thank you in advance.
  7. I have added an "Activate User" functionality to the Virtual Store site. How do I make the user's email address appear in the sidebar "Login" form when the user account is activated; simular to after "Registration" or "Reset Password"? Thank you.
  8. I have added the language functionality from the Forum (PHP and MySQL 4th edition) to the Virtual Store and had to move the Include Config and MYSQL scripts to the header and remove them from the individual scripts. The site's functionality works fine, but does the aforementioned change to the include scrips compromise the security of the site or could it create any other issues? Thank you in advance.
  9. Thank you for your response Larry. I managed to make the select form sticky - apart from my GET/POST error, I also incorrectly used 'lang' instead of 'lid' after the global. The 'stickyness' however disappears when a page is refreshed or a new page is loaded. How can I correct that?
  10. Thank you for your help Larry. I found the complete required lines of code in Script 19.2, "Add a Print - Select an Artist"!
  11. Thank you Larry and Hartley for your very helpful responses. I have 3 more questions if I may. 1. Would the language query still run okay if I moved the language form to the footer? 2. As there are database queries in my site's header, body and footer, can I establish the MySQL connection in the header and close it in the footer, and then just free the results after every query ran by the scripts, then remove all the database connections, where required by the other scripts (i.e. registration), if the header an footer are included? 3. I want to make the language form sticky, but the code (included below) doesn't work, although it works with the other select forms. Am I missing something obvious? // Choose a language: echo '<form action="" method="get" id="language.form"><label for="lang">' . $words['language'] . '</label> <select name="lid">'; // Retrieve all the languages: $q = "SELECT lang_id, lang FROM languages ORDER BY lang ASC"; $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) > 0) { while ($menu_row = mysqli_fetch_array($r, MYSQLI_NUM)) { echo "<option value=\"$menu_row[0]\">$menu_row[1]</option>\n"; // Make form sticky: if (isset($_POST['lang']) && ($_POST['lang'] == $menu_row[0]) ) echo 'selected="selected"'; echo ">$menu_row[1]</option>\n"; } } // Free the results: mysqli_free_result($r); Thanks you in advance.
  12. I am using the below code to get 'countries' for my user registration form instead of hard coding them. The query works but I am however experiencing the following issues: 1. After submitting the completed form it gives the validation error message: "Please select your country." but the "country" list is blank, saved for the word "Country" at the top. <?php // Select a country: echo '<select name="country_id" method="get" id="country_id"> <option value="0">' . $words['country'] . '...</option>'; // Retrieve all the countries: $q = "SELECT country_id, country FROM countries ORDER BY country_eng ASC"; $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) > 0) { while ($menu_row = mysqli_fetch_array($r, MYSQLI_NUM)) { echo "<option value=\"$menu_row[0]\">$menu_row[1]</option>\n"; } } mysqli_free_result($r); echo '</select>'; ?> 2. How can I make the "Country" field sticky? Any advice will be much appreciated.
  13. 1. I removed the "forum.php" from line 115 (pls. see my code below) so that the page does not redirect to the "Forums" page when a new language selection is made. It works, but is this good coding practice and is there a better way to stop the page from redirecting? // For choosing a forum/language: echo '</b><p><form action="" method="get"> <select name="lid"> <option value="0">' . $words['language'] . '</option> '; 2. What changes do I have to implement to the code and database if I want only the languages (and not the word "Language") to appear in the selection field? 3. Is it possible to make the "Language" form to use the selected language simply by selecting it without requiring an input button, using php/html only? I couldn'd find anything on the web, except for a Javascript solution.
  14. Thank you for the code examples and suggestions Margaux and Edward. I applied the code and the registration form works as required. Great forum and book!
  15. Hi Margaux. I applied your code to my table and the tick box is now sticky, thank you! Regarding the validation code that I provided for the check box; that is unfortunately all I could get so far from Larry's PHP book. I just included it with the code of register.php in Chapter 18. I include the email validation code as an example: // Validate and match the email addresses: if (preg_match ('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $trimmed['email1'])) { if ($trimmed['email1'] == $trimmed['email2']) { $e = mysqli_real_escape_string ($dbc, $trimmed['email1']); } else { echo '<p class="error">Your email address did not match the confirmed email address.</p>'; } } else { echo '<p class="error">Please enter your email address.</p>'; } // Validate the terms: if ( !isset($_POST['terms'])) { echo '<p class="error">You must accept the terms and conditions of use.</p>'; } // If the information passed: if ($fn && $ln && $in && $c && $e) {
  16. I have added a "terms" check box to the user registration form in Chapter 18. The registration is successful even if the box is not ticked, although it prints the error message (when not ticked). Also, is there a way to make the "tick box" sticky like the rest of the registration form? I got the code I am using (below) from Larry's "PHP for the Web" book. // Validate the terms: if ( !isset($_POST['terms'])) { echo '<p class="error">You must accept the terms and conditions of use.</p>'; } Table field: <p><input type="checkbox" name="terms" value="Yes" /> I have read, understood and agree to the <a href="terms.php" title="View Terms and Conditions">terms and conditions</a> of use.</p>
  17. Thank you for the advice Hartley and Larry. We will definately incorporate it in our continuity strategy.
  18. Hi HartleySan, Below the link to the article on the 'UTC leap second issue' websites faced at the beginning of July this year I referred to previously. Is there a way of avoiding the UTC leap second issue apart from going the Google route which is most probably out of reach for your avearge web application developer? http://www.dailymail.co.uk/news/article-2167588/Leap-second-2012-Websites-crash-time-hiccup-caused-online-chaos.html Thank you.
  19. Hi HartleySan. Thank you so much for your help. I applied your code and the sorts work perfectly - I just had to add the closing double quotes after the variables to the sort links of the top table row (last snippet of code), which you left out by accident:) Just two related questions: Larry ends the related switch conditional in his book with a 'break' after the default and you left it out, although your code also works perfectly fine. Is the last break necessary? Is the " '$rd_sort = 'rdr' " part of the default code necessary as the "registration date" sorts seem to work perfectly fine without it? Thanks again for your assistance.
  20. Thank you for your reply Hartley. I'm still new at coding so it's more 'cut-and-past' for me than anything else. I tried to change the switch statement and HTML as you suggested without any success. I also had a look at the book's 3rd edition but couldn't find anything to help me. Can you be more specific about the expansion of the switch statement and changes to the HTML code?
  21. Hi Larry, Just want to know if it is possible to make the top column links sort data ascending as well as descending with php as discussed in chapter 10 - and what code do I need to change? Thank you. Apache 2.2.21 PHP 5.3.8 MySQL 5.0.8
  22. Hi Larry, Please advise on how to deal with the UTC time updates (code-wise), that happen every few years. Apparently the 1 second addition to UTC at the beginning of July this year played havoc with some web applications, including some popular social media sites. Regards, Jacques Apache 2.2.21 PHP 5.3.8 MySQL 5.0.8
×
×
  • Create New...