Jump to content
Larry Ullman's Book Forums

margaux

Members
  • Posts

    453
  • Joined

  • Last visited

  • Days Won

    52

Posts posted by margaux

  1. I feel the same way you do Edward. When I first started learning, I didn't understand patterns, now I understand the need for them. I also really grappled with oop. It may slow down the project initially, but will speed up other aspects and also any new ones you start.

     

    Are you using tdd? I've found that really helps but I do still struggle with writing them, particularly controller tests.

     

    Its great that you've stuck with it your project.

    • Upvote 1
  2. Hi Larry

     

    I read with interest in your recent newsletter your plans to publish a new edition of your Javascript book. Having grappled with js for a few years and seen it change hugely, I'm looking forward to the new edition and was very pleased to read that you will be doing more with the advanced material. The language has evolved so quickly that it is hard to keep up and never having spent enough time learning it, I always have to start back at the beginning.

     

    Having read many of your books, I thought I'd give some feedback. 

     

    Your books were one of the first resources I used and one of the few that I stayed with when I started teaching myself web development 4-5 years ago. I regularly recommend them to others. What I like about them is the real world examples with proper code samples and a full explanation of the concepts behind the techniques. I find that I'm able to apply what you've covered to my own projects and I haven't always found that with other resources I've used.

     

    I"m hoping that your new edition will enable me to get to grips with prototypes and closure. Would you be able to include a few examples to practice these concepts? What about including a few examples of using AJAX to work with APIs? I'm also hoping that I'll be able to get more involved in your forums again; having only used ruby and rails for the past year and a half, my php has become very rusty.

     

    Hope the feedback is useful.

     

     

     

  3. Hi

     

    I know these forums are primarily for php users but I'm wondering if any of you also use Rails. After spending the best part of a year working in Ruby and Rails, I've been asked to revisit a php site I built a couple of years ago and add paypal or stripe payments functionality to it. 

     

    How similar is Yii to Rails?

  4. lastIndexOf method returns the position of the LAST occurrence of the string that you specify with the argument. In this example, there are 2 a's so the method returns the position of the last one, just before the 'n'.

     

    The method works by starting its search at the end of the string for efficiency purposes, but the index that is returned is counted from the beginning of the string (starting from 0).

     

    Hope that helps.

    • Upvote 2
  5. If I recall correctly, HTML_QuickForm2 is a class from the pear framework so you need to download any feature you want to use. Then you have to require it in the scripts that use that class. I never completely understood how

    require('HTML/QuickForm2.php');
    

    made it possible for me to use it but I think its because php through php.ini has a list of directories it searches through for files/classes. By installing it you tell php where to find it. I think I followed the steps on the pear site. Sorry I can't be more definite, it was awhile ago.

  6. The php manual tends to be my first go to when I need help with a function but I completely agree with the comments that it is difficult to make sense of. I mainly use it to confirm that I am using the correct parameters in the correct order and am expecting the correct return value. If I need more help, I look at the examples which I learn alot from and check out SO and a couple of other forums.

     

    I don't think I've ever posted on SO but the first time I posted on another forum, the response was pretty harsh, totally not helpful and the responders clearly hadnt even read the question. That experience totally put me off forums in general for awhile but they are good places to learn and get help so I've persevered. This one and thewebdesignforum.co.uk are helpful. So is css-tricks but the php forum is heavily wp biased.

     

    Edward - I've really enjoyed your project diary and have learned alot from it, though I haven't been able to keep up with all of it. You're so right in that there are so many things to learn. I'm currently learning ruby with a view to learning ruby on rails as there is a lot of demand for those skills. If you do get the time occasionally do provide an update, I'm sure many will be interested to see the final product.

    • Upvote 1
  7. @ianhg, that's great that you got it to work. Whilst there is nothing wrong with your code, I hope you don't mind if I make a couple of suggestions.

     

    As is, it won't be easy to maintain so you might want to consider making it more modulable (probably not a word but I'm sure you know what I mean). You could put your functions in a separate file, say functions.php and include that file.

     

    To check for allowed file types - put all the allowed file types into an array, then use the function in_array() to see if the file type is in the array. If you need to allow or disallow a filetype, just add/remove it from the array. Here's a function I created

    function file_allowed($filetype) {
    $filesAllowed = array('image/png','image/jpg','image/jpeg','image/pjpeg','application/x-rar-compressed','application/zip','application/pdf');
    	if (in_array($filetype, $filesAllowed)) {
    		return true;
    	}
    	else {
    		return false;
    	}
    }
    

    Then when you loop through $_FILES, you could replace all that awkward code with

    $count = count($_FILES['ssFile']['size']) 
    for ($i=0; $i<$count; $i++) {
    	if (file_allowed(strstr($_FILES['ssFile']['type'][$i]))) {
    	    $fileAllow="true";
    	}
    	else {
    	    $fileAllow="false";
    	}
    }
    

    Note - I created a count variable so you only count through the $_FILES array once, not every time you run through the loop. For big loops this will help with performance.

     

    I'm not sure $_FILES{'type'] is the best way to access the file type as it is supplied by the browser and can be manipulated. You might want to parse the file name instead.

     

    Hope this helps.

  8. Your script can't find the mysql.inc.php file which is why you're getting the other errors. You need to specify in your include statement the full path to mysql_inc.php using relative or absolute paths. You might want to consider defining a BASE_URL and BASE_URI which is explained in this book.

     

    Also you may need to alter the permissions on your files - I think on windows you do so in the Properties/Security tab, but I'm not really familiar with windows.

  9. I think this line is causing your error

    ?> }  // End of submission IF.
    

    You've closed the php tag before closing the else clause. It needs to be the other way round.

     }  // End of submission IF.
    ?>
    

    Once you've been doing this for awhile, you spot these errors straight away. Also, you might want to consider using a good text editor which provides colour coding and these sorts of errors will be easier to find, particularly if you have long scripts. TextWrangler is pretty good and is free.

     

    Please use code tags when you post code, it makes the post easier to read. Its the <> button on the editing bar.

     

    Hope this helps.

    • Upvote 2
  10. You will want to apply stripslashes() before running the data through mysqli_real_escape_string.

    $message = mysqli_real_escape_string($dbc, stripslashes(strip_tags(trim($_POST['message']))) ) ;
    

    Your query currently is inserting the message directly from the global $_POST, I think you want to change your query to

     $q = "INSERT INTO forum(uname, subject, message, post_date) 
              VALUES ('{$_SESSION['uname']}', '{$_POST['subject']}','$message',NOW() )";
    

    If the apostrophes are still being escaped, check whether magic quotes is enabled.

    • Upvote 1
  11. That's great that you got it working.

     

    HartleySan is right, you need the db connection object as the first parameter for mysqli_real_escape_string. Sorry I forgot that in my earlier post :(

     

    I'm pretty certain this should work

    $country_id = mysqli_real_escape_string($dbc, $coun);
    $q = "SELECT short_name FROM country WHERE country_id = $country_id";
    

    Assuming country_id is set up as the unique primary index on the table with auto_increment you don't strictly need the LIMIT 1 clause, but its worth putting in so the sql engine stops as soon as it finds a match.

     

    Whenever, I'm not sure about the syntax of a function I go to the php manual and look up the function. I struggle with its readability but I do usually find answers and if you scroll down the page, the examples are often very helpful.

     

    You probably found this a bit frustrating but you've learned alot in the process. Good luck with the rest of your project.

    • Upvote 2
×
×
  • Create New...