Jump to content
Larry Ullman's Book Forums

phpstuff

Members
  • Posts

    107
  • Joined

  • Last visited

Everything posted by phpstuff

  1. From #7 bottom of page 126: list($page_title) = mysqli_fetch_array($r, MYSQLI_NUM); Will having dynamic page titles have a negative impact on the pages SEO, or is the page title considered "static" once served?
  2. Can't connect to localhost for some reason. Running MAMP - just updated it. Here is what I have for my config.inc.php file: <?php if (!defined('LIVE')) DEFINE('LIVE', false); DEFINE('CONTACT_EMAIL', 'you@example.com'); // Send error messages to this email address when site is live DEFINE('BASE_URI', '/MAMP/htdocs'); // Should point to the PARENT of the web root directory DEFINE('BASE_URL', 'localhost:8888/'); // eg. www.example.com, localhost:8888/ DEFINE('MYSQL', BASE_URI . '/includes/mysql.inc.php'); session_start(); My mysql.inc.php file is in the includes folder. Any thoughts??
  3. Haven't figured it out yet... Just kept on moving along through the book. Thank you for checking. If I should reference somewhere in this book or your other 2 (PHP, or PHP & MySQL) let me know and I'll go reference those pages.
  4. On the top right of the page it has this tip. How exactly would the code look to accomplish this? Lets say I wanted to insert 2 upper case letters in random positions within the generated password. Thank you for your help.
  5. For #9, "Add user to the database" part of the code is: $q = "INSERT INTO users (username, email, pass, first_name, last_name, date_expires) VALUES ('$u', '$e', '" . password_hash($p, PASSWORD_BCRYPT) . "', '$fn', '$ln', ADDDATE(NOW(), INTERVAL 1 MONTH) )"; $r = mysqli_query($dbc, $q); I'm wondering why there is concatenating going on: '" . password_hash($p, PASSWORD_BCRYPT) . "' What does this benefit? Isn't this info just being dumped into the database as a string?
  6. So it seems like when you hash a password that the hash is a constant related to the password. So, If Amazon.com hashes the user password "mysecretpw99" and the hash is: 1209j09j0939h480h2389g4h9823g4 And then Yahoo.com hashes the same user password "mysecretpw99" then the hash will be: 1209j09j0939h480h2389g4h9823g4 Is this correct? If so, wouldn't it be easy to build a database of potential password combos, hash all of the combos, then have a database filled with hashed values. Then compare those hashed values to the actual hashed passwords that users are using on various websites (assuming the hashed values can be found). Just curious if this is how it works. Are there other techniques available to scramble the hashes or is this not effective or not necessary?
  7. Odd, when I copy/paste the first part of the code I get normal results: CREATE TABLE `categories` ( `id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, `category` VARCHAR(45) NOT NULL, PRIMARY KEY (`id`), UNIQUE INDEX `category_UNIQUE` (`category` ASC) ) ENGINE = InnoDB DEFAULT CHARSET=utf8; This 2nd block of code starts having the issue where it asks for a Y/N confirmation: CREATE TABLE `pages` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `categories_id` SMALLINT UNSIGNED NOT NULL, `title` VARCHAR(100) NOT NULL, `description` TINYTEXT NOT NULL, `content` LONGTEXT NULL, `date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), INDEX `date_created` (`date_created` ASC), INDEX `fk_pages_categories_idx` (`categories_id` ASC), CONSTRAINT `fk_pages_categories` FOREIGN KEY (`categories_id`) REFERENCES `categories` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE = InnoDB DEFAULT CHARSET=utf8; mysql> CREATE TABLE `pages` ( -> `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, -> `categories_id` SMALLINT UNSIGNED NOT NULL, -> `title` VARCHAR(100) NOT NULL, -> `description` TINYTEXT NOT NULL, -> `content` LONGTEXT NULL, -> `date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -> PRIMARY KEY (`id`), -> INDEX `date_created` (`date_created` ASC), -> INDEX `fk_pages_categories_idx` (`categories_id` ASC), -> CONSTRAINT `fk_pages_categories` -> Display all 766 possibilities? (y or n) -> FOREIGN KEY (`categories_id`) -> Display all 766 possibilities? (y or n) -> REFERENCES `categories` (`id`) -> Display all 766 possibilities? (y or n) -> ON DELETE NO ACTION -> Display all 766 possibilities? (y or n) -> ON UPDATE NO ACTION -> ) ENGINE = InnoDB DEFAULT CHARSET=utf8; I did a google search and found: http://www.redhat.com/archives/rhl-list/2005-April/msg03120.html Not sure if it has anything to do with what I'm experiencing... I'm on a Mac so maybe??
  8. I'm glad I now know that it shouldn't do what it's doing above... I'll probably delete the database and start from scratch. Thank you for your help Larry!
  9. I'm actually on the same pages 53-54 getting similar errors, so figured I'd add to this same post - updating my MySQl version may fix the error aboce, but I'm getting a wierd error below. This happened when I copied / pasted (ctrl-v) into terminal...I didn't even hit "enter" and it looks like it started trying to run the code. mysql> CREATE TABLE `pages` ( -> `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, -> `categories_id` SMALLINT UNSIGNED NOT NULL, -> `title` VARCHAR(100) NOT NULL, -> `description` TINYTEXT NOT NULL, -> `content` LONGTEXT NULL, -> `date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -> PRIMARY KEY (`id`), -> INDEX `date_created` (`date_created` ASC), -> INDEX `fk_pages_categories_idx` (`categories_id` ASC), -> CONSTRAINT `fk_pages_categories` -> Display all 749 possibilities? (y or n) -> FOREIGN KEY (`categories_id`) -> Display all 749 possibilities? (y or n) -> REFERENCES `categories` (`id`) -> Display all 749 possibilities? (y or n) -> ON DELETE NO ACTION -> Display all 749 possibilities? (y or n) -> ON UPDATE NO ACTION -> ) ENGINE = InnoDB DEFAULT CHARSET=utf8;
  10. What percentage of the time on average would you use the Switch conditional vs. the else conditional?
  11. Thank you both very much for taking time out of your day to reply. I kinda feel like I'm whining a bit, and maybe I am, but I'm really wanting to see how people approach learning this stuff. This is a personal goal that will bring great satisfation once I'm there so I will never give up that is for sure. Once I finish this book 100% and review it, I'll be moving on to ecommerce and simultaneously working on the PHP/MYSQL for the website I designed...hopefully with this forum and the books I'll be able to knock out my first site... Thanks again for the positive words here.
  12. Ok...so I've read Larry's first PHP book, and now I'm in the last chapter of the 2nd PHP book. I've bought also Larry's OOP book (but was told to wait and go through the ecommerce book 1st which I think is probably a good idea) as well as Javascript and ecommerce v2. I'm planning on going over this 2nd PHP book again (skim through, review, take notes, etc) and then go through the ecommerce book v2. My question for everyone out there is how long did it take you to start to pick up PHP at say the "moderate/intermediate" level? 2 years, 3 years, 5 years? I started in Jan 2013 and now its April 2014, I did take off a few months so I'd say I'm roughly 1 year into studying (and ~2 books) - I usually pick everything up fairly quickly but not so here... I'm understanding some concepts and patterns but it seems like there is SO MUCH to have to learn and memorize its overwhelming at times. I went to college for finance and I must say this is much more difficult than college! Perhaps its the self-paced without a teacher thing that is difficult... Anyways just wanting to get a gauge of how everybody else has approached learning this stuff. I'm not going to give up, but, I just don't know if maybe I need to focus on 1 component per week or??? Please feel free to throw suggestions my way. I've heard many say "you need to practice by building sites" and I do have a site that I designed from scratch that I also built in HTML/CSS that's waiting for PHP/MYSQL so I want to pursue that but I'm just seeing if there are any other techniques or suggestions as stop and reflect back over the last year.
  13. How would I check that the required file is being received? Is the below correct? I basically copy/pasted from the link you provided from php.net above. I ran this in my browser and just got a white screen - does that mean I don't have an error since it didn't print an error message? <?php # test_database_connection(ch19).php // This page tests for a connection to the database require ('../mysqli_connect(ch19).php'); // check connection - **TAKEN DIRECTLY FROM THE PHP.net SITE if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } ?>
  14. Hi all, Getting errors which I think are related to the connection to the DB, but not sure. I double checked all the code again just now and it should be perfect. I went through the entire chapter's scripts, now going back through making corrections - I have 19.2 correct but I can't proceed because 19.1 is required since you have to upload artist name in order to populate the dropdown in 19.2. I did some searching online for these errors and most were related to normal parenthesis / quotes etc which, again, I believe the code to be 100% correct. Any help here is certainly appreciated - hoping to wrap up this chapter this week, then re-review the entire book, and then move on to the recently purchased effortless ecommerce v2! Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in /Applications/MAMP/htdocs/PHP_MYSQL/add_artist(19.1).php on line 25 Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in /Applications/MAMP/htdocs/PHP_MYSQL/add_artist(19.1).php on line 26 Warning: mysqli_stmt_affected_rows() expects parameter 1 to be mysqli_stmt, boolean given in /Applications/MAMP/htdocs/PHP_MYSQL/add_artist(19.1).php on line 29 Warning: mysqli_stmt_close() expects parameter 1 to be mysqli_stmt, boolean given in /Applications/MAMP/htdocs/PHP_MYSQL/add_artist(19.1).php on line 37 <!DOCTYPE html> <head> <meta http-equiv="content-type"content="text/html; charset=utf-8" /> <title>Add an Artist</title> </head> <body> <?php # Script 19.1 - add_artist(19.1).php ************THIS ENTIRE PAGE IS CORRECT - CHECKED ON 3-30-14**************** // This page allows the admin to add a new artist name to the database if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Handle the form // Validate the first and middle names (neither required): $fn = (!empty($_POST['first_name'])) ? trim($_POST['first_name']) : NULL; $mn = (!empty($_POST['middle_name'])) ? trim($_POST['middle_name']) : NULL; // Check for a last_name... if (!empty($_POST['last_name'])) { $ln = trim($_POST['last_name']); // Add the artist to the database: require ('../mysqli_connect(ch19).php'); //////////////////////////////////////////// $q = 'INSERT INTO artists (first_name, middle_name, last_name) VALUES (?,?,?)'; $stmt = mysqli_prepare($dbc, $q); mysqli_stmt_bind_param($stmt, 'sss', $fn, $mn, $ln); mysqli_stmt_execute($stmt); // Check the results... if (mysqli_stmt_affected_rows($stmt) == 1) { echo '<p>The artist has been added.</p>'; $_POST = array(); } else { // Error! $error = 'The new artist could not be added to the database!'; } // Close this prepared statement: mysqli_stmt_close($stmt); mysqli_close($dbc); // Close the database connection } else { // No last name value. $error = 'Please enter the artist\'s name!'; } } // End of the submission IF. // Check for an error and print it: if (isset($error)) { echo '<h1>Error</h1> <p style="font-weight: bold; color: #C00">' . $error . ' Please try again.</p>'; } // Display the form... ?> <h1>Add a Print</h1> <form action="add_artist(19.1).php" method="post"> <fieldset><legend>Fill out the form to add an artist:</legend> <p><b>First Name:</b> <input type="text" name="first_name" size="10" maxlength="20" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p> <p><b>Middle Name:</b> <input type="text" name="middle_name" size="10" maxlength="20" value="<?php if (isset($_POST['middle_name'])) echo $_POST['middle_name']; ?>" /></p> <p><b>Last Name:</b> <input type="text" name="last_name" size="10" maxlength="40" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p> </fieldset> <div align="center"><input type="submit" name="submit" value="Submit" /></div> </form> </body> </html>
  15. Thank you both for your replies... I will use my own images, etc - thanks again!
  16. Not looking for code, I'm looking for the print photos, print descriptions, print prices (to populate and test database). Or....do I just manually do this?
  17. I'm confused (could be lack of sleep) as to where the database data comes from in this chapter (tried to change title to reflect the better wording but I"m locked from editing it). Are we expected to type in random names and upload random photos to populate the database? The book doesn't seem to specify unless I'm missing something...I've been flipping pages for an hour..
  18. Nice explanation, I especially like this part: Also note that numbers are added together with a plus sign, and strings are added together with a period. Makes it click in your head nicely!
  19. Thank you for your time in your response here Larry. I'll check this out - I'm sure I should have provided extra code but at the end of the book there are so many pages of code I just hoped that the error would prompt somebody familiar to point me in the right direction.
  20. LOL...sorry, I almost felt something like that coming, and then it came, better than I expected..
  21. Ok, so I took a chance and added ISSET to the footer file, and I think it worked! Can somebody explain why it now works and shows no errors? Is this errata or not? This version works - to make it work I added: if (isset($_SESSION['user_level'])) { } <!-- START of Header --> </div><!-- Content --> <div id="Menu"> <a href="index.php" title="Home Page">Home</a><br /> <?php # Script 18.2 - footer_ch18.html // This page completes the HTML template // Display links based upon the login status if (isset($_SESSION['user_id'])) { echo '<a href="logout.php" title="Logout">Logout</a><br /> <a href="change_password.php" title="Change Your Password">Change Password</a><br /> '; // Add links if the user is an ADMIN if (isset($_SESSION['user_level'])) { if ($_SESSION['user_level'] == 1) { echo '<a href="view_users.php" title="View All Users">View Users</a><br /> <a href="#">Some Admin Page</a><br /> '; } } } else { // Not logged in. echo '<a href="register.php" title="Register for the site">Register</a><br /> <a href="login.php" title="Login">Login</a><br /> <a href="forgot_password.php" title="Password Retrieval">Retrieve Password</a><br /> '; } ?> <a href="#">Some Page</a><br /> <a href="#">Another Page</a><br /> </div><!-- Menu --> </body> </html> <?php // Flush the buffered output. ob_end_flush(); ?>
×
×
  • Create New...