Jump to content
Larry Ullman's Book Forums

Antonio Conte

  • Content Count

  • Joined

  • Last visited

  • Days Won


Everything posted by Antonio Conte

  1. It could very well be, yes. I'm betting you'll find libraries already written for handling image uploads, so that'll spare you a lot of hours of development time. The same applies to other frameworks, which is one of the reasons you'd maybe want to use one. The drawback is generally time spent learning how to use the framework, but a book will help speed that up. There's no absolute truth here, so spend time doing some research and make up your mind that way. Playing with YII or another framework for a couple of days might pay off in the end.
  2. Your last thought is the right one. This is a one-to-many relationship that needs an table like employeesDeptartments. Larry writes about this in the sub-chapter starting at page 109. (Or thereabout - Larry has released lots of versions so far.)
  3. To add detail, PHP has a series of global arrays for HTTP request. $_POST is filled with POST data, $_GET with GET and $_REQUEST is a combination of them both. $_REQUEST is thus the least explicit of them of them all, and that's why you need to check if the request method is POST first. When you deal with just POST request, ($_POST) you already know that. It is therefor considered "cleaner" or more specific.
  4. The first tip to give you is to download an IDE with PHP support. That will highlight errors in your script for you, provide auto completion of functions as you type, and other nice things. A lot of them are free to. Check out one of the following: - Eclipse - Netbeans to your problem. Undefined variable is not really a constant. That's an error message. It'll happen if you try to use a not previously declared variable in a structure which requires that. In simpler terms, if you feed a variable that does not exist to an if statement, a function or similar, you'll get that error message. I'll demonstrate it: // Undeclared $iDoNotExistYet if ( $iDoNotExistYet) { // You'll get an undeclared variable error. } //...Code below illustrates another script // Here we declare a variable $iDoExist = true; if ( $iDoExist ) { // I exists/Is declared. This is true } Check out the code above. Your error is due to the problem illustrated in the first example, as explained.
  5. That is almost correct. The mail function takes a total of 5 params, where the last to is optional. It basically has this format: mail ( $mailTo, $subject, $message, $headers, $params ) In your case, I would alter it to something like this: // Set from address $from = "me@myisp.co.uk"; // Assign subject $user = isset($_SESSION['uaname']) ? $_SESSION['uaname'] : ""; $subject = "Posting added by " . $user; // Build here message $message = "very long message"; $message = wordwrap($message, 70, "\r\n", true); // Create header $headers = 'To:'. $mailto . PHP_EOL; $headers.= 'From:' . $mailfrom . PHP_EOL; // Finally, send mail $status = mail($from, $subject, $message, $headers); // Some simple debugging echo $status ? "The Email was successfully sent" : "mail function failed"; Just build the subject and message string as you want, and you should be pretty much good to go. Btw. Remember to check the PHP manual. You can find lots of information on mail() here: http://php.net/manual/en/function.mail.php
  6. Yes, they are case sensitive. The easiest way to avoid problems with that is to download JS syntax highlighting to your IDE/Programming software, install Firebug in Firefox to catch any errors that way, to check your code using something like Jsbin.com (built in syntax highlighting) or by using jslint.com. Glad you solved it. Nice work.
  7. You do have some pitfalls here. The last parameter you add ("From: $uname") does: 1.) Not exists. Optional headers, your $messageproper, is the last valid param you can specify. 2.) Is not a valid From address. According to RFC 2047, you need to specify it using one of the following formats: user@example.com user@example.com, anotheruser@example.com User <user@example.com> User <user@example.com>, Another User <anotheruser@example.com> Optional headers. You cannot apply headers the way you are doing it. The "From:" header should be set either here or in your php.ini, and should only include valid headers such as "To:", "bbc:" and the likes. Because they are headers (what makes computers understand the content of the packages you send) you need to be very careful to follow formats. If the receiver can't understand headers, packages will be dropped... Apply the content of both the $mailto and the $mailfrom (a variable I add below) in the specific format I specified above. Try something like this: $headers = 'To: '. $mailto . PHP_EOL; $headers .= 'From: ' . $mailfrom . PHP_EOL; // $header .= ... additional headers here... The next one is line endings. Instead of using LF, try doing CRLF endings instead. ("\r\n") However, some Linux servers will struggle with that, even if it's the RFC 2047 recommendation. The trick is to use the PHP constant PHP_EOL instead of setting your line endings manually. That will let your server apply the needed line endings automatically. Weird code Don't add unnecessary parenthesis to your strings or spaces before your ending semi-colons. No-one I've ever seen writes code like that, and it can potentially introduce bugs or parse errors. Only use parenthesis when it's necessary (casting) and remove them otherwise. Hope that helps you out.
  8. Ok. I have downloaded and checked the code now. Calculator.html should work without Calculator.php. There might be several reasons why this is not the case, thought. 1. Make sure you include the jQuery framework. - Basicly make sure the "js" folder is located at the same path as Calculator.html. The easiest way to check this is to view the document source in Firefox (right click and find view source) and try to click the link to jquery.js. If that doesn't work, your browser won't be able to find the JS file neither. Move the folder or change your path until it works.2 2. Make sure you include calculator.js - This is the file that "overloads" or progressively enhances the user experience. As with the jQuery.js file, make sure it's reachable for your browser, using the same methods. If non of that solves the problem, try to download the book resources one more time and ask again if that doesn't work... Within this file, you find a line looking like this: // Assign an event handler to the form: $('#calculator').submit(function() { ... That line will prevent your browser from doing a request to calculator.php, but will instead let the JavaScript do the calculation. However, If that line is not available (js file not found) or jQuery is not loaded (then $('#calculator') won't register the event handler correctly) the script will post to calculator.php in the end. That's what progressive enhanchement is all about. 3. The 404 message - This is not the reason why your Javascript does not work. However, you still need that file as a fallback solution, should your JS fail or something along does line happen. Make sure your file hierarchy looks along these lines - calculator.html - calculator.php - js / jquery-1.6-1.min.js - js / calculator.js Hope that helps you out.
  9. Looks like I took a wrong guess here. Will post more later today, but you basically get a 404 as calculate.php does not exists.
  10. You are correct in most cases, but when it comes to Ajax request, you need the PHP file to get the correct response from your request. This is not a browser issue, (most likely) and I would bet you'd get the same response using Opera, Chrome or Safari too.
  11. Keep in mind most things in PHP and MySQL acts as a String even though the value is of the integer type. Try typecasting or parsing the value to an integer before anything else. Try something along the lines of... $row = mysqli_fetch_array($result, $dbc); $_SESSION['id'] = (int) $row['user_id'];
  12. My tip would be you need to use one of the commands listed. Try adding parse or run after your phpdoc command.
  13. Sometimes, I thank god I'm on a provider that does this kinda stuff for me. I had to install some locals a couple of months ago, and only had to snap my fingers! (And write an email) Good work solving this one.
  14. Nice solution. You write some really good code, Edward. The only thing I don't get is the array in your method? Why not do simple String concatenation instead of imploding an array in the end? My reasoning for adding exception handling is more about my Java background. If you have uncaught exceptions in Java, your programs will crash, so it's become something of a habit. I tend to always catch exceptions, even when it's not strictly needed. Thanks for the nice words about the site. The site is pretty much finished, and we will remove dummy data and start advertising the system quite soon. Dark eyes are the dominant gene, so blue eyes requires both parents to at least have a recessive blue gene, and for that to be "picked". The same with blond hair. My sister got brown hair and blue eyes, and we have the same parents of course.
  15. Glad you worked that one out. I did something very similar to you with a time range difference function, but with conjugations for the human-readable output. That means 1 hour - 2 hours, 1 second, 2 seconds, etc. I also added different output depending on how much time is remaining. It'll return days, hours, minutes or minutes and seconds when time < 10 min. I added a small gist here for you: https://gist.github.com/thomaslarsson/6029616 The class is not really good code by any stretch of the imagination, but it does the trick for me. Would love to see your solution for this too.
  16. Glad you solved it and thanks for the reassurance. Nice way to solve the problem btw. Clean, simple solution. I like it.
  17. Well. You laugh of me for not solving your problem in 15 minutes and you most likely called me "Dr." sarcastically. Why shouldn't I take offense to that? I HAVE given you a way to handle the functionality you describe, but most likely YOU can implement it way faster than me. It's as simple as that you know YII — I don't... You can't expect me to pull a fully functional implementation of this out of my ass on the spot. 1. Functionality goes into your extended base model 2. Set a protected flag property in the base model to turn auto timestamps on and off. 3. Write a protected method like getUpdatedTimeStamp. It could look something like this: protected function getUpdatedTimeStamp() { $datetime = new DateTime("now"); return $datetime->getTimeStamp(); } 4. Implement a method for the onAfterSave filter. (or similar) 5. In that method, check if the flag is set. 6. If the flag is set, assign the timestamp method to the updated_at property 7. Save the model again. The alternative is to use other filters like beforeSave, if that makes sense. You could possibly do the assigning of timestamps in one operation. Again, Edward. This is the way I would solve things personally. I don't know if that's the perfect way, but it WILL work. As I stated earlier, if nothing else works (namely the possibly tried and tested solutions you find online) this is at least a simple way to implement it. I don't know YII, and won't pretend I know it's ins and outs. In lack of solutions, and since you asked, I tried to be a nice guy and gave you a general purpose solution that will most likely work. I don't think I deserve the tone you are giving me.
  18. What's with the attitude? You ask a question, get some possible solutions, turn them down and ridicule me? I'm not a YII master an has never pretended to be. What's your problem?
  19. Then just format the DateTime object like a timestamp? Not really a problem.
  20. If everything else fails, you could build a solution into your base model. Hook into something like the afterSave filter (or what it is called) and do a manual update using a formated DateTime object.
  21. The preferred option is generally composer now. Pear is a piece of garbage, and you can often find alternatives. I did a quick search for form builders on github, and found one with potential. It should do pretty much the same as Quickform2, without knowing exactly what that did. Er du norsk forresten?
  22. I like CodeIgniter's documentation too, but I find it a little too less concise some of the time. It's hard to strike the perfect balance for everyone, I guess. I don't really have more to suggest. To exaggerate, I woke up one day and it all suddenly made sense. I guess it's one of those stepping-stones kind of thing where you reach a certain level of understatement, and it's beginning to makes sense from that point on. Good luck moving forward though. Maybe someone have something else to add?
  23. This problem is related to packages and your include path. As you see from your error message, the file does not exists at your include_path. When you require/include files, PHP will check several places for that file if it's not found. When it can't find QuickForm2.php inside the folder named "HTML", it'll then check your include path. That's why you get that message there. If you turn on "view hidden files" on your computer, go do your C drive, then navigate through the folders /usr /local /pear /share /pear, that's where you computer expects the Pear package to be downloaded at. You might do one of several things to fix the problem: 1. Change include_path in php.ini: (Recommended) - Find your php.ini file and change the include_path variable to where the HTML QuickForm package is located. 2. Change include_path with ini_set() - Add this line before you include something. It'll change your include path temporarily for that script. ini_set("include_path", "new/path/here"); 3. Move your package. Find it using search, copy it and paste it into usr/local/pear/share/pear
  24. Reading documentation and manuals are horrible, but you get used to it after a while. One trick is to ignore all explanations and look at input params, return values and examples first. Knowing data types and structures are often also important. You notice the manual type hinted the first param as a "callable" in array_map? The type text is also a link, so looking at that would possibly make your life simpler. Doing such cross-referencing is very important. Btw. The PHP manual is horrible compared to that of some other languages. I hope they fix a lot of that with the recent improvements of php.net.
  • Create New...