Jump to content
Larry Ullman's Book Forums

eonfloyde

Members
  • Posts

    14
  • Joined

  • Last visited

Everything posted by eonfloyde

  1. A little confused, sorry... After looking at the above closer I am thinking my way may be easier to add or subtract from the menu that isn't part of the drop down? I use an 'if' to choose the array in which to dynamically create the main links (not via drop down menu). Can you explain where you would add this code to my original? I see only the drop down menu portion as a option. If I am not mistaken the original code is dynamically creating the links (main menu portion) from the $pages array? I could add register to the drop down portion, but for usability I think I would like it more obvious? I may not fully understand the suggestion.
  2. I Think your way is easier and better, but I did not think of that. I finally got it to work this way. But it sure is a lot less code via your example. Thank you very much for your reply. It took me some time to figure this out. I should keep the KISS method in mind from now on. :-) -eon-
  3. Oh shoot I did it this way. Which is better practice? <?php // Dynamically create header menus. // Array of labels and pages (without extensions): // Show or hide register.php link if user is logged in via session data: if (!isset($_SESSION['user_id'])){ $pages = array ( 'Home' => 'index.php', 'About' => '#', 'Contact' => '#', 'Register' => 'register.php' ); }else{ $pages = array( 'Home' => 'index.php', 'About' => '#', 'Contact' => '#' ); }
  4. Question: I have never created a menu system dynamically. I can not figure out how to hide() the register tab if a user is logged in. I am unsure where to start in the header file to do so. Near the bottom of the code is where we decide if we should show the log in page within the index page. I figure I would have to start there, or change the dynamic code to check for this first? I'm such a newbie... LOL Any help, or ideas would be most appreciated. Thank you, The Code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content=""> <meta name="author" content=""> <title><?php // Use a default page title if one was not provided... if (isset($page_title)) { echo $page_title; } else { echo 'Knowledge is Power: And It Pays to Know'; } ?></title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <!-- Bootstrap core CSS --> <link href="css/bootstrap.min.css" rel="stylesheet"> <!-- Custom styles for this template --> <link href="css/sticky-footer-navbar.css" rel="stylesheet"> </head> <body> <!-- Wrap all page content here --> <div id="wrap"> <!-- Fixed navbar --> <div class="navbar navbar-fixed-top"> <div class="container"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="index.php">Knowledge is Power</a> <div class="nav-collapse collapse"> <ul class="nav navbar-nav"> <?php // Dynamically create header menus... // Array of labels and pages (without extensions): $pages = array ( 'Home' => 'index.php', 'About' => '#', 'Contact' => '#', 'Register' => 'register.php' ); // The page being viewed: $this_page = basename($_SERVER['PHP_SELF']); // Create each menu item: foreach ($pages as $k => $v) { // Start the item: echo '<li'; // Add the class if it's the current page: if ($this_page == $v) echo ' class="active"'; // Complete the item: echo '><a href="' . $v . '">' . $k . '</a></li> '; } // End of FOREACH loop. // Show the user options: if (isset($_SESSION['user_id'])) { // Show basic user options: // Includes references to some bonus material discussed in Part Four! echo '<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Account <b class="caret"></b></a> <ul class="dropdown-menu"> <li><a href="logout.php">Logout</a></li> <li><a href="renew.php">Renew</a></li> <li><a href="change_password.php">Change Password</a></li> <li><a href="favorites.php">Favorites</a></li> <li><a href="recommendations.php">Recommendations</a></li> </ul> </li>'; // Show admin options, if appropriate: if (isset($_SESSION['user_admin'])) { echo '<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Admin <b class="caret"></b></a> <ul class="dropdown-menu"> <li><a href="add_page.php">Add Page</a></li> <li><a href="add_pdf.php">Add PDF</a></li> <li><a href="#">Something else here</a></li> </ul> </li>'; } } // user_id not set. ?> </ul> </div><!--/.nav-collapse --> </div><!--/container--> </div><!--/navbar--> <!-- Begin page content --> <div class="container"> <div class="row"> <div class="col-3"> <h3 class="text-success">Content</h3> <div class="list-group"> <?php // Dynamically generate the content links: $q = 'SELECT * FROM categories ORDER BY category'; $r = mysqli_query($dbc, $q); while (list($id, $category) = mysqli_fetch_array($r, MYSQLI_NUM)) { echo '<a href="category.php?id=' . $id . '" class="list-group-item" title="' . $category . '">' . htmlspecialchars($category) . ' </a>'; } ?> <a href="pdfs.php" class="list-group-item" title="PDFs">PDF Guides </a> </div><!--/list-group--> <?php // Should we show the login form? if (!isset($_SESSION['user_id'])) { require('login_form.inc.php'); } //I figure here is where I could add an (isset($_SESSION['user_id']. hide() or something. I can't figure it out. ?> </div><!--/col-3--> <div class="col-9"> <!-- CONTENT --> 0 Quote MultiQuote Edit
  5. Thank you for your post! This has helped me to understand better what may have happened. I had zero problem logging in, adding pages. However, as you point out I did have an issue when trying to view the pages. I was told that I had to renew (that I had expired). (BTW - this is in relation to login.inc.php line 52 which affects category.php line 35) However, what I did was change the comparison operator form === to == and problem fixed. I am unsure what PHP is returning, and unsure if each version is returning something different. The PHP manual says: $a == $b Equal TRUE if $a is equal to $b after type juggling. $a === $b Identical TRUE if $a is equal to $b, and they are of the same type. Maybe something to do with PHP casting differences in each version? I have no idea, such a newbie here... but I am curios. My guess is one is an INT and the other a String? Retrieved From: http://php.net/manual/en/language.operators.comparison.php
  6. Question: I have never created a menu system dynamically. I can not figure out how to hide() the register tab if a user is logged in. I am unsure where to start in the header file to do so. Near the bottom of the code is where we decide if we should show the log in page within the index page. I figure I would have to start there, or change the dynamic code to check for this first? I'm such a newbie... LOL Any help, or ideas would be most appreciated. Thank you, The Code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content=""> <meta name="author" content=""> <title><?php // Use a default page title if one was not provided... if (isset($page_title)) { echo $page_title; } else { echo 'Knowledge is Power: And It Pays to Know'; } ?></title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <!-- Bootstrap core CSS --> <link href="css/bootstrap.min.css" rel="stylesheet"> <!-- Custom styles for this template --> <link href="css/sticky-footer-navbar.css" rel="stylesheet"> </head> <body> <!-- Wrap all page content here --> <div id="wrap"> <!-- Fixed navbar --> <div class="navbar navbar-fixed-top"> <div class="container"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="index.php">Knowledge is Power</a> <div class="nav-collapse collapse"> <ul class="nav navbar-nav"> <?php // Dynamically create header menus... // Array of labels and pages (without extensions): $pages = array ( 'Home' => 'index.php', 'About' => '#', 'Contact' => '#', 'Register' => 'register.php' ); // The page being viewed: $this_page = basename($_SERVER['PHP_SELF']); // Create each menu item: foreach ($pages as $k => $v) { // Start the item: echo '<li'; // Add the class if it's the current page: if ($this_page == $v) echo ' class="active"'; // Complete the item: echo '><a href="' . $v . '">' . $k . '</a></li> '; } // End of FOREACH loop. // Show the user options: if (isset($_SESSION['user_id'])) { // Show basic user options: // Includes references to some bonus material discussed in Part Four! echo '<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Account <b class="caret"></b></a> <ul class="dropdown-menu"> <li><a href="logout.php">Logout</a></li> <li><a href="renew.php">Renew</a></li> <li><a href="change_password.php">Change Password</a></li> <li><a href="favorites.php">Favorites</a></li> <li><a href="recommendations.php">Recommendations</a></li> </ul> </li>'; // Show admin options, if appropriate: if (isset($_SESSION['user_admin'])) { echo '<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Admin <b class="caret"></b></a> <ul class="dropdown-menu"> <li><a href="add_page.php">Add Page</a></li> <li><a href="add_pdf.php">Add PDF</a></li> <li><a href="#">Something else here</a></li> </ul> </li>'; } } // user_id not set. ?> </ul> </div><!--/.nav-collapse --> </div><!--/container--> </div><!--/navbar--> <!-- Begin page content --> <div class="container"> <div class="row"> <div class="col-3"> <h3 class="text-success">Content</h3> <div class="list-group"> <?php // Dynamically generate the content links: $q = 'SELECT * FROM categories ORDER BY category'; $r = mysqli_query($dbc, $q); while (list($id, $category) = mysqli_fetch_array($r, MYSQLI_NUM)) { echo '<a href="category.php?id=' . $id . '" class="list-group-item" title="' . $category . '">' . htmlspecialchars($category) . ' </a>'; } ?> <a href="pdfs.php" class="list-group-item" title="PDFs">PDF Guides </a> </div><!--/list-group--> <?php // Should we show the login form? if (!isset($_SESSION['user_id'])) { require('login_form.inc.php'); } //I figure here is where I could add an (islet($_SESSION['user_id']. hide() or something. I can't figure it out. ?> </div><!--/col-3--> <div class="col-9"> <!-- CONTENT -->
  7. Larry, Loving the book!! Your a genius.. :-) I just wanted to say that in my book (Effortless E-Commerce: second edition) on page 93-94 just before the we create the "IF" to determine whether the email, or username is at fault when validating the script. Line 127 of your supplied code shows an "ELSE" before the "IF" on line 129, which the book does not. I checked the books forum for an errata but none exists. I don't know if this will help anyone, but it did me as my code would not validate the culprit (username, or email, or both). This may help those following along coding by hand? Thanks, and I look forward to buying the Yii book, looks interesting. -eon-
  8. Sorry, I forgot to list my versions: PHP 5.5.14 MySQL 5.5.38 OSX 10.9.4 In addition this is all I could find on the subject. Can't say I completely understand if this will hurt the way the database will function for future chapters. MySQL auto initialises TIMESTAMP Columns with DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, so your first column TIME has the CURRENT_TIMESTAMP Added as default. Therefore by the time you explicitly add a DEFAULT to a column one already exists. You either need to change the order your columns are defined: CREATE TABLE `silas`.`cs3_ds1` ( `ID` INT NOT NULL , `INSERT_TIME` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP , `TIME` TIMESTAMP NOT NULL , `USER` VARCHAR(45) NOT NULL , `TIME1` TIMESTAMP NOT NULL , `TIME2` TIMESTAMP NOT NULL , PRIMARY KEY (`ID`) ) ENGINE = InnoDB Or add defaults to your other timestamp columns: CREATE TABLE `silas`.`cs3_ds1` ( `ID` INT NOT NULL , `TIME` TIMESTAMP NOT NULL DEFAULT 0, `USER` VARCHAR(45) NOT NULL DEFAULT 0, `TIME1` TIMESTAMP NOT NULL DEFAULT 0 , `TIME2` TIMESTAMP NOT NULL DEFAULT 0 , `INSERT_TIME` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP , PRIMARY KEY (`ID`) ) ENGINE = InnoDB FOUND AT: http://stackoverflow.com/questions/11031946/getting-only-one-timestamp-column-with-current-timestamp-in-default-or-on-updat
  9. no sir, I am talking about PHP and MySQL for dynamic websites fourth edition.
  10. I am really enjoying your books. They focus on may concerns for todays systems. Especially security. Thanks for taking the time to write them. I finished PHP and MySQL for dynamic web sites. I found great information throughout that title. I have now started this book (effortless eCommerce 2nd ed.), which is very intriguing. I started the book, and ran into a strange issue. The very first SQL script failed on 'users' table. The exception I received; 16:24:57 CREATE TABLE `users` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `type` ENUM('member','admin') NOT NULL DEFAULT 'member', `username` VARCHAR(45) NOT NULL, `email` VARCHAR(80) NOT NULL, `pass` VARCHAR(255) NOT NULL, `first_name` VARCHAR(45) NOT NULL, `last_name` VARCHAR(45) NOT NULL, `date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `date_expires` DATE NOT NULL, `date_modified` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE INDEX `username_UNIQUE` (`username` ASC), UNIQUE INDEX `email_UNIQUE` (`email` ASC), INDEX `login` (`email` ASC, `pass` ASC) ) ENGINE = InnoDB DEFAULT CHARSET=utf8 Error Code: 1293. Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause 0.000 sec I figured I did something wrong, so I tried again this time using the downloaded script, and exact same error occurred. In addition, the errata seems to be missing from the website, if there is an errata? I searched the forum to find that not one person has seen this issue. I am wondering if my MySQL is malfunctioning... I can not determine where the problem lies. Any help wold be much appreciated. Please advise... Thank you for your time, -Mike-
  11. That makes sense, I'll get it... Thank you for answering my previous question. Now a poetncially really stupid question: I see page 473-478 we use javascript to control the pages error handling. We use calculator.html, calculator.js, and calculator.php (and a new version of the css document). I am very curious how this works. I can test to see that javascript is handling the new error reporting because the errors show up on the page (no alert window). This thwarts the calculator.php page attempt at handling the errors because we use false to prevent actual form submission. However, when we submit is javascript doing the calculation, or calculator.php? What I am trying to wrap my head around is : the form from the calculator.html still calls calculator.php to do the calculations, or is calculator.js doing the calculations? I test by changing the math on the .php version and the results are different. When I change them on the .js version they are the same. I am thinking that calculator.php is doing the math which leads me to be a little confused as to why calculator.js has the same math in it? Can you clarify what is happening? I sure hope this makes sense.
  12. I need some help on Chapter 13 Review and pursue. Instead of posting a new topic I thought I place it here. Page 432 the last "Pursue" challenge: "Apply the Fileinfo extension to the show_image.php script from Chapter 11". I can not figure out how to do this. I have only been using the original script. I do not see how to use the resource (file info) once created. I believe I need to apply this resource to $name = $_GET['image'], but am unsure how this would work as this is a function, and the show_image.php is a script that images.php validates from. Any ideas on how to pursue this challenge? I sure wish I could figure it out. Thanks in advance for any ideas, or help understanding the Fileinfo extension. Mike
  13. Okay.. After several attempts to figure out the issue with this script the problem was basic syntax, and mail server postfix issue using MAMP 3.0. Specifically, my XHTML was missing the " = " for method = "post" within the form element. After reviewing the debugging steps in chapter 8, and using other sources of information, the script is now functional. The issue with MAMP PRO; because the syntax problem within the XHTML the script simply did not execute. I received no errors, and was not able to use 'echo' statements for debugging because the script never ran. I focused to hard on two problems at once with out slowing down and identifying that the XHTML syntax was correct. I do not know how I missed that several times, but I did. Once the XHTML issue was found, the script functioned, which allowed me to properly input my domain extension into MAMP PRO 3.0 (yourdomain@com). Lesson = step through each part of your code before identifying, or trying to solve another problem. I was able to test my server and new something was wrong, but without my script working properly I was not able to fix the secondary issue (the postfix problem). Hope this helps someone...
  14. Larry, I love your books, I have learned more from them than I did from actual classes... LOL Thank you for taking the time to help us out when we run into problems. I appreciate your knowledge. Please excuse my way of asking questions, as I am new and find it a bit difficult to make sense of it all. I am new to PHP. I can build static sites, but PHP syntax messes with me; even my HTML at times.. I am having a heck of a time figuring out why Chapter 11 : Script 11.1 will not function. I have read many forums, searching out possible causes. The script displays, will run, but nothing happens. For instance when submitting, I can see the data populate the URL, but no "thank you" or "error" message appears. The script just hangs (URL never changes, appears to just hang at the below http in browser window bar). URL: (http://localhost/PHPandMySQLBook/ch3Site/email.php? name=Me&email=some%40email.com&comments=TESTING+123+&submit=Send!) The form resets ($_POST = array() ) is working. I have also tried using your script and modifying the email address (using my own) to no avail. I have tested a very simple script locally that works fine. $msg = "First line of text\nSecond line of text"; $msg = wordwrap($msg, 70); mail("my@email.com", "My Subject", $msg); When previewing the above simple script in my browser I receive the email (Mac Mail). I have also attempted to use a remote copy of the script, to no avail. In addition, I have tried MAMP pro to see if Postfix would help the script function: to no avail. I do not believe it is my 'send mail' method at this point. In addition, I have tried changing the php.ini file to include my user/bin/my@email.com, but may not fully understand what it is I am truly doing. Furthermore, I have read appendix A, but it is difficult at best to follow with my newer version of PHP (PHP admin looks completely different). I am a newbie obviously, and could use some help debugging the problem. Or some help in searching the web for a solution. I do not understand 'postfix' or how it may affect my computer if settings are changed. I have stepped away several times to avoid over analyzing, I have rewritten the script, I have used the books script, I have uploaded to my ISP, and tried locally. Nothing seems to work except the above simple script. My next line of thinking is to try an simplify the script adding one little piece at a time until it breaks? You are correct Debugging has a serious learning curve.. Thank you in advance. I am using: DreamWeaver CS6 (in code mode, with Testing Server MAMP, and Remote via FTP all functional) MAMP 3.0.5 PHP VERSION = 5.5.10 Mac OSX Mavericks 10.9.4 My current script: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Contact Me</title> </head> <body> <h1>Contact Me</h1> <?php # Script 11.1 - email.php # DO NOT RELY ON THIS SCRIPT AS HACKERS CAN AND WILL USE IT TO SPAM. RATHER REFER TO FUTURE CHAPTER CHANGES. if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!empty($_POST['name']) && !empty ($_POST['email']) && !empty ($_POST['comments']) ){ //Create the body $body = "Name: {$_POST['name']}\n\n Comments: {$_POST['comments']}"; //limit line lentgh $body = wordwrap($body, 70); //Send the email mail('my@email.com', 'Contact Form Submission', $body, "FROM: {_POST['email']}"); //This I change to //my email which works for above simple mail() script. //if it worked OK echo '<p><em>Thank you for contactin me. I will reply some day.</em></p>'; //Clear the array $_POST = array(); }else{ //Error message if it didn't work OK. echo '<p style="font-weight: bold; color: #COO">Please fill out the form completely.</p>'; } } ?> <!--Begin the form--> <p>Please fill out this form to contact me.</p> <form action"email.php" method"post"> <p>Name: <input type="text" name="name" size="30" maxlength="60" vlaue="<?php if(isset($_POST['name'])) echo $_POST['name']; ?>" /></p> <p>Email Address: <input type="text" name="email" size="30" maxlength="80" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>" /></p> <p>Comments:<textarea name="comments" rows="5" cols="30"><?php if(isset($_POST['comments'])) echo $_POST['comments']; ?> </textarea></p> <p><input type="submit" name="submit" value="Send!" /></p> </form> </body> </html>
×
×
  • Create New...