Jump to content
Larry Ullman's Book Forums


  • Content Count

  • Joined

  • Last visited

  • Days Won


old.graham last won the day on February 23 2014

old.graham had the most liked content!

Community Reputation

4 Neutral

About old.graham

  • Rank
  1. Thank you to Deaddog for his view_users.php (script 10.5) code which solved a problem for me. I wanted to switch form ASC to DESC for the lists, and got about halfway there, but this solved the problem for me. I have altered it slightly to suit my own requirements but gave honourable mention in the comments.
  2. Hi Larry, Thank you for your very prompt reply. I take it then that finfo_file() is going to depend on browser variety? Firefox may possibly give different results from IE or Chrome? I guess then that finfo_file() would be the one to use where the file's attributes/MIME type is critical. Gratitude for unravelling that. old.graham
  3. Hi and thanks in advance. I run apache 2.2.22 , php 5.3.10-10 in Ubuntu 12.04. I have been working through the chapter13 Review and Pursue topics . The Pursue 4/5th topics suggest modifying the upload_rtf.php code. I have added code to display the name, type and size of a file that has been offered for uploading. I get some unexpected and inconsistent results for MIME types for an RTF file type and also some other file types. The relevant code is: //indicate it's OK: also print file MIME type echo '<p><em>The ' . finfo_file($fileinfo, $_FILES['upload']['tmp_name
  4. Hi again, and a good new year to all. I have been working away at chapters 11 and 12 and the Review and Pursue sections. Most of the answers that I came up with for chapter 11 are too long for inclusion in the forum, so I have stuck them as usual in my site at www.visitingfife.co.uk/computers along with the usual caveats. Chapter 12 answers are (so far) a lot shorter, so here are my stabs at them. The first bit is a couple of attempts at item 6 of the review, function returning multiple values. <?php function demoReturn($rock, $gem, $soil){//create some parameters if(!empty($rock) &
  5. Finally, I get it. Thanks for the second post, Larry. That was the one that clinched it for me. I had the same problem as HartleySan and had to read the posts several times. Still puzzled, I walked away from it and had a Eureka moment about an hour later. My code above is unnecessary. You don't have to force the error to be string or array, but I wouldn't have got it without all the input from the Advanced Members. All the best for the New Year to you all.
  6. After my less than useful last post, I thought about it overnight. I came up with this. Is this the sort of thing that would satisfy the question? <?php //define variables //$wrong1 = 'This the wrong1'; $wrong1 = ''; //$wrong2 = 'This is the wrong2'; $wrong2 = ''; if(empty($wrong1)){//if var is empty assign message to var $err1 = 'Wrong1 empty.'; }else{//no worries echo 'Wrong1 is right<br />'; } if(empty($wrong2)){//if var is empty assign message to var $err2 = 'Wrong2 is empty'; }else{//no worries echo 'Wrong2 is right<br />'; } if(empty($wrong1) && empty($wrong
  7. Hi Victor, I read your comment on my solution for the "handle_errors.php" yesterday and that really gave me pause for thought. I tested it in one of my scripts, then I tested it again removing the final ?> as you said. Both work without any obvious error. I suspect that you may well have the right of it but I would be interested to hear from Advanced Members or even Larry on this. I have had a quick look through your answer(s) for the Pursue Chapter 10 and on my first glance you've come up with similar solutions to myself which reassuring for me. I guess if it works then it is probably OK
  8. I have been slowly working my way through the chapter 10 Pursue section and have pretty much completed it, but as I mentioned above on 16 October, the coded solutions are much too big for this forum. They seem to work OK but I make no guarantees that the code could not be better written! I have published them as pdf files at http://www.visitingfife.co.uk/computers/index.html. I have had to add data to the database to make the code work realistically. If anyone wants the edited tables, then I can be mailed at old.graham@gmail.com.
  9. I finally got around to chapter 10 Review and Pursue section after getting VERY sidetracked with chapter 9 Review and Pursue, banking database. I haven't added any error checking just to keep it simple. In order to get the edit.php and delete_user.php to display the user name in the browser title bar (and also the header because it looks good) I found that I had to change some lines in the view_user.php script. Lines 76-86 (page 324) I replaced with: while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){ extract($row);/*this allows variables with the same name as the $row['something
  10. Hi Antonio, Thanks for looking in again. Earlier in the script each of the user inputs are treated thus: //check for first name if(empty($_POST['first_name'])){ $errors[] = 'You forgot to enter your first name'; }else{ $fn = mysqli_real_escape_string($dbc, trim($_POST['first_name'])); //validate user input } Is this enough or should there be further checks on input? I have seen forums where prepared statements are recommended, but that looks a bit advanced for this forum _ and for me _ as yet.
  11. Thanks for the suggestion. I have altered all the relevant code in my IDE to help me remember that. I now make my offering for Q4 page 298 using mysqli_affected _rows(). I have just posted what I believe to be the relevant bit. Hope I got this OK. //make the query $query = "INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES ('$fn', '$ln', '$email', SHA1('$password'), NOW() )"; $request = @mysqli_query ($dbc, $query);//run the query if (mysqli_affected_rows($dbc) == 1){//if it ran OK should be 1 row only changed //display message echo '<h1>Thank you!
  12. Hi Antonio, Does this fit the bill? //check for email if(empty($_POST['email'])){ $errors[] = 'You did not enter your email.'; }else{ $email = mysqli_escape_string($dbc, trim($_POST['email'])); //this is escaped bit //make a query to check if email is already in use $q = "SELECT user_id FROM users WHERE email = '$email'"; $r = @mysqli_query($dbc, $q); $n_rows = mysqli_num_rows($r); if ($n_rows > 0){ $errors[] = 'This email address is already in use.'; }else{ $email = mysqli_escape_string($dbc, trim($_POST['email'])); }//end if email already in use }//end if empty email Thanks for
  13. Hi Antonio, Thanks for the heads up on that, but it has me really puzzled _ unless you mean the error suppressor operator? If that is what you mean then you are quite correct and I should have it in. That would then be $r = @mysqli_query($dbc, $q); If that's not it, can you be more explicit because I can't think what else it could be? Thanking you in advance and mea culpa for the fault. I have just noticed another error in the code. I have inserted the code fragment in the wrong place. It should go in line 33. As it was, it only works if all the other inputs have been filled. I
  14. Hi Larry, Thanks for your comment. But your book really makes it so easy I can take very little credit. Any road up, here is my solution to the 4th question on the chapter 9 Pursue and Review using mysqli_num_rows() function to test for previous use of the email address. //make a query to check if email is already in use $q = "SELECT user_id FROM users WHERE email = '$email'"; $r = mysqli_query($dbc, $q); $n_rows = mysqli_num_rows($r); if ($n_rows > 0){ $errors[] = 'This email address is already in use.'; }else{ $email = mysqli_escape_string($dbc, trim($_POST['email'])); }//end if ema
  • Create New...