Jump to content
Larry Ullman's Book Forums

chop

Members
  • Content Count

    192
  • Joined

  • Last visited

  • Days Won

    5

chop last won the day on August 8 2015

chop had the most liked content!

Community Reputation

10 Good

About chop

  • Rank
    Advanced Member
  1. Correction the the above post. To clarify, if I want to order the output by the town in which a particular pet was lost (column= town_lost) AND at the same time not get duplicate data returned (because there may be many returns in the "town_lost" column that are not unique) I have to include the unique column "pet_id" which is my primary key. The correct way to do this is: $order_by = 'town_lost ASC, pet_id'; with the primary key being the second sort and with no ASC or DESC In other words, Larry had it correct... sorry Larry!
  2. Yes, exactly! This worked perfectly: $order_by = 'pet_id DESC, town_lost DESC'; First, order by the primary key "pet_id", then the town names (it's really towns I use not states) follow in the same order. No duplication, no missed data. I never knew I could nest one ORDER BY inside another. thanks!
  3. I have run into a bit of a problem where I get repeated row results on separate pages within a paginated SELECT query. It works okay if I sort on, say, the unique "pet_id" column. But if I SELECT and sort by a column that can have similar items in the column (such as sort by state), it's very possible that results for row 15 (which comes up on page 4), for example, also shows up on page 7. This is a problem not just because things are repeated within the same query, but also, because I am using "LIMIT $start, $display", and if one $result row gets on the page twice, that means that another row (that should appear) is not getting on at all! I tried using SELECT DISTINCT but, of course, that is for a use within a single query. Every page number in the pagination scheme is a separate query. Thanks for any offerings. chop
  4. On page 516 script 16.9: Line 20: setcookie (session .... //DESTROYS COOKIE This line destroys a cookie set earlier (that was set in login.php? or in the Header?) However I cannot find the corresponding cookie that was set. The value, i see, is PHPSESSID thank you Also, is it always necessary to set a cookie when using a Session?
  5. My book is PHP 6 and MySQL 5, though it doesn't have an edition printed on it (copyright 2008). I might be in the wrong forum but the 3rd edition forum for this book doesn't seem to be active. That said, I am in chapter 16, looking at the code for login.php. I can't find any code for setting cookies in it though the logout.php has the code for destroying the cookies. Unless my eyes have gone buggy, I just can't find it. It seems like the login relies just on sessions. Also, login.php page does print the text "Your browser must allow cookies in order to log in" What am I missing?
  6. Thanks, Larry - I'm glad to hear you say it's tricky. I felt like I was asking another dumb question because it seemed like it should be easy. Too bad I just can't set NULL as a default for the whole column. That would make it easy, then write over it with the md5() when it should be validated. Anyway, I'll probably keep the code as 2 queries written under two conditionals. If I've learned nothing else about programming, it's that code should be easy to understand at first glance after not seeing it for a few months. It might come at the cost of a few extra lines of code but, if I am able to immediately see the logic, it's worth it. P.S. My PHP6 and MySQL5 book is in several chunks now after having rebound it twice. I admit I've not been easy on it though. Hope to get a newer version some day when one comes out (??) chop
  7. Is is possible to Insert a NULL value into a table by assigning it to a variable. For a low level user I want the activated column to have the following inserted: $a = md5( uniqid( rand(), true ) ); // put 32 char code into column "activated" for email verification But for a higher level user, I don't want them to have to verify their email address. So I thought I could set $a = "NULL" or $a= NULL I only end up with the word NULL instead a real null . I also thought there might be away of setting the column to default to NULL. Then the md5 () would write over it and that would solve the problem. But I couldn't do that either. Now I just have two separate INSERT queries under a conditional with a "SET activated=NULL" for one of them. It works, but I hate writing the code twice. thanks, chop
  8. Okay, I found it.. a <?php ?> in the line above. I think you probably meant I "could" be printing something instead of "should". thanks
  9. I should mention that there is an index.html it should go to. Also, I have tried it with a specific page.php as part of the location.
  10. Sorry, I copied it incorrectly. The code is as follows. Also, I don't know what you mean when you say "print". Do you mean a php print statemet? What is the purpose of that? $url = 'index.php'; // Define the URL. echo "Hello, I should be redirecting now..."; header('Location: https://tenthousandeyes.org'); exit(); // Quit the script.
  11. I've used header() a hundred times. For some reason this just gives me a blank screen. The url exists and the script gets into the conditional and exits. This is a modification of Larry's script in chapter 16 that I get get to work because of this. thanks very much if (!isset($_SESSION['first_name']) || $_SESSION['user_level'] == 0 ) { echo "Hello, I should be redirecting now..."; header('Location: https://tenthousandeyes.org/.php'); exit(); // Quit the script. }
  12. I'm getting old... It's not the code that's at fault, it's the non-code. That is the lack of code in line number 1, which is blank. A blank space outside of any <?php ?> tags is also known as "whitespace". I swore I'd never fall victim to whitespace again after the first 3 times. header() cannot follow any whitespace, ever. header() cannot follow any whitespace, ever. header() cannot follow ANY whitespace, ever. Officially, the php documentation: "Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file" There. That should do it! It is now my mantra. It will never happen again... really
  13. Here is a snippet of code right out of this book. I have been using it for years and it has always worked. Now, it just seems to die on me. It is supposed to take me from login.php to logged in.php. Instead, it goes to the line right after the header(), prints it and stops via exit(). The url in the browser still shows I am at login.php. There are no errors generated. After I log in with login.php (and it stops without going to loggedin.php), I will type the url for loggedin.php directly into the browser and it will get me to loggedin.php with the session already running. I.E., the privileges will all be set. So why isn't "login.php" redirecting me to "loggedin.php"? <?php # Script 11.8 - login.php #3 USING SESSIONS if (isset($_POST['submitted'])) { require_once ('includes/login_functions.inc.php'); require_once (CONNECTION); list ($check, $data) = check_login($dbc, $_POST['email'], $_POST['pass']); if ($check) { // OK! // Set the session data:. //session_name('glee');// this will refer to the last session by name instead of starting a new one ob_start();// start output buffering session_start(); $_SESSION['user_id'] = $data['user_id']; $_SESSION['first_name'] = $data['first_name']; $_SESSION['last_name'] = $data['last_name']; $name = $_SESSION['first_name'].$_SESSION['last_name']; // Redirect: $url = absolute_url ('loggedin.php'); //line below isn't working even though the value for $url is //http://localhost:8888/sites_in_progress/gill_truslowBS4/loggedin.php //(which is correct) header("Location:$url"); ob_end_clean();// stop output buffering echo "We have now gone past the header() function and are still at login.php"; exit(); } else { // Unsuccessful! $errors = $data; } mysqli_close($dbc); } // End of the main submit conditional. include ('includes/login_page.inc.php'); // THIS INCLUDES HEADER.HTML ?>
  14. Hi Larry- I just noticed that you have PHP for the Web 5th edition available last month. I have a couple of questions: 1. An Amazon preview of the book is avail. for Kindle but not paperback. Is there much difference in content between the two? Much rather have the physical book. 2. I own PHP 6 and MySQL 5. Though mySQL is not in the title of PHP for the Web 5th edition, it has chapters on it. So, what is the main difference between the two? From what I understand, you are due to come out with the next edition of PHP (without the 6) and MySQL 5 this fall. In light of the fact that I already own the former version, would I, in your opinion, be better off to wait for the new version or purchase the PHP for the Web 5th edition book. Most of my interest is in building websites. thanks, (p.s.) My current copy has been through hell with my cats and having been out for a day in a thunderstorm. Thanks to Shoe Goo and some heavy cloth repair material, it is still usable but I feel it has earned at least a sem-retirement status.
  15. Peter- I don't know the answer to your first question but, as for the second (and I assume you are talking about using it for PHP code), no, don't use Word. Use a plain text editor. such as notepad. Better yet, get a free code editor that will give you the functions you need most like code highlighting and line numbering etc. Do a search for "Best free php code editors" or maybe someone here can suggest something for Windows, if that's what you are using.
×