Jump to content
Larry Ullman's Book Forums


  • Content Count

  • Joined

  • Last visited

  • Days Won


Everything posted by old.graham

  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
  15. Another post: solution to Chapter 9 Review and Pursue, Pursue topic 3: In view_users.php: To use the mysqli_num_rows($result) as a boolean value to test TRUE, I simply removed line 19 if ($num > 0 ){//if any records returned and substituted if (mysqli_num_rows($result)){ Very simple _ and it seems to work all right.
  16. Just posting my solution to Chapter 9 Review and Pursue, Pursue topic 2 _ Custom error handler : It seemed the easiest way to do this was to strip the handle_errors.php script of everything that wasn't inside the php tags,and remove line 36 and save the revised script in the same folder as the other php scripts as handle_error.php. I then added to view_users.php on line 6 include ('handle_errors.php'); which is under line 5 includes ('header.php'); then added on line 7 set_error_handler ('my_error_handler'); The new 'handle_errors.php' <?php #script 8.2 - display errors define(
  17. Hi Rafaec, I haven't got as far as you in the book so I can't answer your question. I've just been posting here what I think might be the answers to the Review and Pursue. Like you I am not always sure what Larry has in mind when he asks the questions. Could be the questions are just to make sure you have thought the thing through and are familiar with the code ideas and concepts and there are no hard answers? Larry will no doubt answer this better than anyone. Anyhow here is my take on chapter 3's last 3 questions which I have concatenated into one script. <?php function create_radio
  18. The whole new form would be too much for a forum, so I have limited the new form to just the textarea and checkbox not described in the book. <?php # A solution to Review and Pursue chapter 3 page 110: Create a new sticky form. # I have supplied a header.html and footer.html to accompany this form. # The css I submitted above works with this form. # The form looked a bit bland, so I have included additional styling in the header.html file # rather than rewrite the whole of the css file. # I am indebted to http://www.phpfreaks.com/forums/index.php?topic=139571.0 boo_lolly for check
  19. ...and here is the footer ... <!--end of page specific content--> <!--rewritten for Review and Pursue chapter3: footer.html--> </div> <div id="footer"> <p>Copyright © <a href="#">Awfy Simple</a> 2012 | Designed by <a href="http://www.opendesigns.org/">Old Graham </a> | Valid <a href="http://jigsaw.w3.org/css-validator/">CSS</a> & <a href="http://validator.w3.org/">XHTML </a></p> </div> </body>
  20. Thanks for replying so quickly. Sorry. I can see that adding code piecemeal might be a bit confusing. It takes me ages to format the code so that it is easier to read since I don't seem to be able to paste it with the formatting that gedit or Aptana provide. The css goes with the ability to change the look of the entire site. The previous css file would be named style.css to work with the header. The footer follows shortly. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
  21. Hi Larry, First offering for chapter 3... I have followed the formatting used by gedit in Linux (Ubuntu) so I hope that this is more readable. Thanks for your kind comments on my trade. /*Review and Pursue chapter 3 page 110 PHP and MySQL edition4 *This is a new css template for use on pages in chapter 3 *author old.graham June 2012 */ body{ margin:auto; border: 0px; padding: 0px; background: #EBECF6; width: 950px; } a{ text-decoration: none; color: #4A2885; } a:hover{ color: blue; } #header{ border-style:solid; border-width: 2px;
  22. I will be happy with any advice you feel able to give and try to follow it. I hoped that the code and your comments and advice on this code would be of help to me and other readers/student PHP code writers who have difficulty with the Pursue pages or are curious about other ways of doing things. I shall have a look at using forum formatting tags on the code and in an attempt to make it more readable. The formatting (line spacing and tab/margins) in the IDE I use (Aptana on Ubuntu 10) seems to get lost when I cut and paste. In the past when I have been stuck with a problem, I have found mayb
  23. Oops. I should have put in some /n to make the source code readable. Thought of it just after I posted. Apologies.
  24. Thanks for the comments and for taking the time to reply. The double quotes was just silly of me. I wish I had thought of using the number _format that way. Just good style from a pro. I shall take on board the variable names comments. I have now got some more. The code for the ch 2 review and pursue is getting kind of big for posting here but I shall await your feedback on this. I suppose if it is just copied and pasted into and IDE it will be more readable. I hope this may be of some use to someone. I await your feedback with trepidation. PHP version? <!DOCTYPE html PUBLI
  • Create New...