Jump to content
Larry Ullman's Book Forums

Antonio Conte

  • Content Count

  • Joined

  • Last visited

  • Days Won


Everything posted by Antonio Conte

  1. I think that's a good idea, and I've done the same thing when I had to refactor a procedurally coded site recently.
  2. One solution might be to convert the documents to PDF files. This thread on StackOverflow gives you some clues on how to do it: - http://stackoverflow.com/questions/5538584/convert-word-doc-docx-and-excel-xls-xlsx-to-pdf-with-php
  3. The version of PHPMyAdmin is not really important, but your MySQL version might not support stored procedures. You need at least MySQL 5.1 and the correct privileges on your user to create procedures.
  4. Get them from Amazon. They should have the PDFs or whatever, right? Larry's on there. I agree with you that Peach Press makes it too damn hard to sign up. I had to google those US postal codes to signup as a Norwegian citizen. Guess they don't want foreign customers, huh.
  5. Normalization is a process. You need to start what you need to do with the data, and normalize it from there. If you don't need location data for anything but displaying it to the user, you might as well save it in human-readable form on the museum itself. If you need to filter/sort the museums in regards to continents, countries or regions, you'll need separate tables for them all. With that said, if sorting/filtering is all you need to do with locations, a hybrid solution might do the trick. I.e, you save both a human-readable location on the museum and save foreign keys to the location parts. The way to solve the problem with looking at data, creating views that display that information is what you need to do. There's several ways to solve a sorting/filtering issue. You might do a simple Autocomplete textfield against the human-readable location, or sort them by a nested data structures that updates based on previous selections in drop-down lists. You are correct about the latter part. That is one of the reasons why you'd want to normalize the data properly. To summarize, you need to explain your use cases a little more in detail for us to really help you out. Your use cases/future uses cases are the most important aspect for how to normalize the data.
  6. I would agree with that. The second step with general validation is what I usually go for.
  7. This might be because NetBeans tries to debug footer.php on it's own and don't keep the variables from the old script in memory. If that's not the problem, I have no idea. If the goal is to ensure that everything is working correctly, you might want to look into Unit testing with PHPUnit. You'll find some good sources on NetTuts and Youtube as examples.
  8. Try putting these in the top of your script: ini_set('display_errors', true); ini_set('error_reporting', -1); They might reveal some errors that are currently supressed/silenced on your end.
  9. What is a valid email address? That's a really important question. I'm actually allowed to create the following email addresses on my host: _@juvenorge.com _._@juvenorge.com !@juvenorge.com #@juvenorge.com $@juvenorge.com =@juvenorge.com ?@juvenorge.com ^@juvenorge.com I don't know if these are regarded as valid generally, but that being said, I can create them and probably send and receive emails from them. That at least brings up a few interesting questions for you to answer.
  10. I don't really agree with you that C++ is losing ground. When performance is key, there's often no better suit than C++ or even C itself. Professional programmers are most likely using the language best suited for the job, and OOP is not always the perfect fit for everything. Especially in graphic intensive programs, like games, C/C++ is still going really strong. They still do teach C/C++ in universes here in Oslo, Norway, along with C# and Java. I agree with you that learning a fully object-oriented language can be a good way to learn. I have a Java background myself, and it definitely made me a better programmer. That said, what really gave me some solid programming experience was learning about Algorithms and data structures. That is language-agnostic knowledge you can bring to every language you must write in. Design patterns is also one of those words that fly around from time to time. However, learning best-practices and having a solid understanding of how to solve most programming problems is invaluable in my experience. I'm not yet a professional programmer, but I'll be looking for jobs shortly. To kind of summarize, I suggest you find a good book about Algorithms and data structures in your language of choice. If that's C#, I recommend you do that. Keep in mind that knowing that specific language itself won't help you in the long run, but learning how to program in general will. As I've said, I learned using Java, but have helped friends writing C# without any experience in the language. The reason why I've been able to do that is general programming knowledge.
  11. One of the simplest ways to do this is to initilize two database connection variables in your mysql.php script. When you perform queries on the second database, use the new variable instead. <?php # mysqli.php $dbc = mysli_connect( ... ); // You know the drill. $other = mysqli_connect( ... ); // The details for the new connection Inside your scripts, you can now use both $dbc and $other require "mysql.php"; // Require connection script $query = "SELECT * from someTable"; $result = mysqli_query($dbc, $query); // Using the "standard" connection $query = "SELECT * from someOtherTable"; $result = mysqli_query($other, $query); // Using the "other" connection Keep in mind that the mysql functions are deprecated. You should switch to mysqli. Most functions are almost identical, though.
  12. Where is $string comming from? You can't treat a variable like $string equal to $_GET['string'] og $_POST['string']. It won't exist unless you actively initiate it above your if statements. $string = "someting" if ( isset($string) ) { echo "Awesome"; } // Yeah! By the looks of it, your code will immediately go to the else statement and execute from there. Make sure your indention is correct, though, because it's really hard to scan your code without proper indentation. My first thought is to add echo statements to your code an see what's running and what's left out. Deploy that tactic, and you'll get a better sense of what's really happening. I'm also betting on that Jon will post a better response soon. Seems like he's been following the thread more closely than me. Good luck.
  13. If you are dealing with currency or other things that really requires precision, you need to look up "the money pattern". It's a design pattern invented to deal with precision in floating point number calculations, and do often have conversion capabilities. The basic premise is that you have a unit like dollars, kilometer, miles, gallons, liters or whatever. The pattern is well-known, and you should be able to find it in books, maybe some videos and some free articles. I recommend you start out with this one on NetTuts. It will also explain some basic TDD, which will be really helpful when you deal with this kind of stuff. Because precision is so prone to bugs, and bugs really should never happen when dealing with precision, TDD is almost a must here. - http://net.tutsplus.com/tutorials/php/money-pattern-the-right-way-to-represent-value-unit-pairs/ Keep the moral high btw. Believe in yourself, I know you can do this.
  14. The calling class would be the class used to call the method from. Inside class Dog, self::prop; would equal Dog::prop etc. It's really hard to understand what you doing here without seeing your code, but my feeling is that your code shouldn't really be static. Static methods doesn't really allow for inheritance. The accepted answer in this Stack Overflow gives you some context: http://stackoverflow.com/questions/532754/inheritance-of-static-members-in-php
  15. As stated on PHP.net, self:: refers to the calling class. http://www.php.net/manual/en/language.oop5.late-static-bindings.php
  16. The design and CSS is not really the point of the book. Without being totally sure, I think Larry even used external sources for anything in that regard. I would deem this "a non-issue", even if the CSS actually have some problems. It's not really the point here. With that said, I'm sure he appreciates you taking your time and sharing potential problematic code though. Good find.
  17. Install it using Composer instead. Composer is "the new Pear". Books get outdated and composer is the new de-facto standard for package management in PHP. Considering your error message, you need to do exactly as the error message says. Add phpdoc to the line "include_path" in your php.ini file. I would instead install composer and download the package from packagist.com thought. Composer: http://getcomposer.org/ PHPDocumentor: https://packagist.org/packages/phpdocumentor/phpdocumentor Youtube tutorial: http://www.youtube.com/watch?v=Ejr4Xqs9V2I
  18. What you need here is planning. You already have a specific goal and a reason for learning how to program. I would thus suggest you look into something called agile development. While it may sound like one of those fancy buzzwords flying around - and maybe it is to some degree - it will give your project a sorely needed structure. I'm not a sales man and won't try giving you a pitch here. In short, agile development is a framework and a toolbox to help you with planning small programming project for smaller teams. You break everything in the project down into smaller pieces (implementing tournament types, match events or point rules) and set individual deadlines and milestones for those parts. This will allow you to plan out each piece of the puzzle individually and will allow you to track progress in a better way. It will also force you to make sacrifices (do I have time for the fancy feature, or should I drop it?) and keep your head focused on the goal. Agile development might not fit your needs, but make sure you at least deploy some kind of structural system to the development. It's a vital step to make sure everything doesn't boil down to nothing. I'm a huge football fan btw, so this sounds like a fun project. I don't really know what you are doing here, but feel free to contact me if you are considering co-developers. I'm currently working on something that shares a lot of the common codebase to your project. Forza Juve!
  19. Remove the NOT NULL DEFAULT CURRENT_TIMESTAMP from your date_modified column. MySQL doesn't allow two columns to current_timestamp on inserts for some weird reason. The insert will thus result null, while it'll update the timestamp on update queries. I don't know if this will break anything in the application, but that'll fix your import errors at least.
  20. True that considering your hypothetical case. You'd need to build stock availability checks into your code, but you should do that no matter what. The code remembering issue is fixed by adding constants/an options array to your class. Product::UNLIMITED_STOCK, etc. Preventing such bugs is a valid reason for sticking to enums though. Another column is a good solution, so stick to that if that seems most comfortable. It's not anything bad with such a solution.
  21. It's definitely an important point. I'll let Larry give his input on the matter, but you know my thoughts. The null value issue can be solved by using the signed integers as codes and not allowing nulls. This is what I've done in similar cases. Also If you want to do any programmatically with the stock value, I would also go for a TINYINT as boolean rather than textual enums. If you only need them for textual stuff I see no problem. Anyway. I know you got this. Just my two cents based on recent experiences.
  22. You can't have ANY ouput to the browser before a redirect, not even a doctype or other non-viewable elements. Take a look at how Larry generally structure his scripts. In this specific case, this should work out for you: <?php # Script 12.1 - email.php #2 /* The function takes one argument: a string. * The function returns a clean version of the string. * The clean version may be either an empty string or * just the removal of all newline characters. */ function spam_scrubber($value) { // List of very bad values: $very_bad = array('to:', 'cc:', 'bcc:', 'content-type:', 'mime-version:', 'multipart-mixed:', 'content-transfer-encoding:'); // If any of the very bad strings are in // the submitted value, return an empty string: foreach ($very_bad as $v) { if (stripos($value, $v) !== false) return ''; } // Replace any newline characters with spaces: $value = str_replace(array( "\r", "\n", "%0a", "%0d"), ' ', $value); // Return the value: return trim($value); } // End of spam_scrubber() function. // Check for form submission: if (isset($_POST['submitted'])) { // Clean the form data: $scrubbed = array_map('spam_scrubber', $_POST); // Minimal form validation: if (!empty($scrubbed['name']) && !empty($scrubbed['email']) && !empty($scrubbed['comments']) ) { // Create the body: $body = "Name: {$scrubbed['name']}\n\nComments: {$scrubbed['comments']}"; $body = wordwrap($body, 70); // Send the email: mail('example@example.com', 'Contact Form Submission', $body, "From: {$scrubbed['email']}"); // Print a message: header("Location: thankyou.htm"); exit(); } else { $message = 'Please fill out the form completely.'; } } // End of main isset() IF. ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Contact Me</title> </head> <body> <h1>Contact Me</h1> <p style="font-weight: bold; color: #C00"><?php if (isset($message)) echo $message; ?></p> <p>Please fill out this form to contact me.</p> <form action="test-email-fresh.php" method="post"> <p>Name: <input type="text" name="name" size="30" maxlength="60" value="<?php if (isset($_POST['name'])) echo $_POST['name']; ?>" /></p> <p>Email Address: <input type="text" name="email" size="30" maxlength="80" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p> <p>Comments: <textarea name="comments" rows="5" cols="30"><?php if (isset($_POST['comments'])) echo $_POST['comments']; ?></textarea></p> <p><input type="submit" name="submit" value="Send!" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> </body> </html> Notice how I bind the output to $message instead of echoing it directly. Also see that all HTML is below the PHP. As PHP is executed top-to-bottom, that makes all the difference. Also, try not to mix HTML into your PHP code. Let styling be in you HTML.
  23. You are outputting HTML to the browser before you run the PHP. That's your problem here. Assign things to variables instead of echoing the out directly, and echo the variables inside your HTML instead. Also move any HTML below the PHP logic.
  • Create New...