Jump to content
Larry Ullman's Book Forums

Larry

Administrators
  • Posts

    5413
  • Joined

  • Last visited

  • Days Won

    155

Everything posted by Larry

  1. You're not really providing enough information here (see the guidelines), but if you're loading header.html directly in your browser, you're going to see the raw code. Also, to be clear, this book does assume complete comfort with PHP and MySQL.
  2. Well, it's always safer to use a separate system for administration but that doesn't mean it's necessary. It's just a matter of what's the appropriate level of security for the situation. With what you describe, it doesn't sound like it's necessary to use a separate folder and system.
  3. I normally use the term "INDEX" in my SQL but phpMyAdmin outputs SQL commands using "KEY", which is why you'll sometimes see "KEY" in the book.
  4. You'll also see that result if the update works but doesn't actually change any of the stored values, in which case the number of affected rows will be 0.
  5. Perhaps there are benefits to using fopen() et al. that I'm unaware of, but my inclination would be to just use readfile().
  6. I don't personally see what the problem is with onChange or lost focus. If you must do onKeyUp, I'd call a function onKeyUp, but then only execute the first Ajax request if the value is greater than X characters long. Then you'd also need to create a system so that subsequent keyup events don't trigger another request. You could use a flag variable for this. Or only do an Ajax request onkeyup every 4 or 5 characters.
  7. In theory, you could do that, but I'd recommend opening phpMyAdmin on the existing computer and exporting the entire set of databases, except for the mysql database. Then install XAMPP on the new computer and use phpMyAdmin there to import them. If you have too much data (like over a couple of megabytes), you can't important that in phpMyAdmin, in which case using the command line mysql_dump and mysql_import would be the way to go.
  8. For what it's worth, I would never perform an Ajax request onKeyUp. That's just crazy. If a username is 10 characters long, you'd perform 10 requests while entering that? No good. Whatever you're witnessing on a local or small site, Ajax requests onKeyUp is not tenable on a good live site. That's my opinion, anyway.
  9. No, that conditional will only be true if $test has a "true" value, meaning it exists and isn't equal to false or an empty string or 0 or NULL. If you want to test for a variable's existence, you'd use isset(). Variables do not have default values in PHP. As for Script 16.6, without looking at the script, I'm fairly sure it would also work if you set the variable equal to NULL.
  10. Both. Always make sure columns used as the basis of JOINs have indexes on them (on both). Good question!
  11. Yes, that's correct. In that example, MySQL could find the row you're looking for by only looking at the first three characters, which is much more efficient. And you're quite welcome!
  12. Glad that's working for you. I think with ISPs, you can generally use their mail server without authentication if you're using the associated email address because the request is coming from inside the same network: i.e., a message sent from an @isp address from within the ISP's network is legit.
  13. Have you confirmed the values of the variables? In other words, if you print out the query being executed by PHP is it the exact same?
  14. Good question. == is the equality operator and === is the identical operator. For example 0 and "0" are equal in PHP but they are not identical. The same goes for 0 and FALSE: equal, not identical. Conversely, != is the not equals operator and !== is the not identical operator. Since 0 can be interpreted as false, using != false wouldn't fix the bug, because 0 does equal false. By using !==, the conditional confirms that the returned result isn't FALSE, specifically.
  15. Thanks again for catching this. It was a bug in the code and I'll add a note to the errata page after I post this reply. The code in question is this: $qty = (filter_var($qty, FILTER_VALIDATE_INT, array('min_range' => 0))) ? $qty : 1; What the code is supposed to do is assign the value of $qty to the $qty variable if it's an integer greater than 0. If not, the value 1 should be assigned to $qty. To understand that bug, we've got to think about how filter_var() works and how conditionals work in PHP. The filter_var() will return the filtered data, if it works, or FALSE. With a $qty value of 0, filter_var() will return 0. In PHP, the conditional if (0) { is FALSE. So, in such cases, $qty is assigned the value of 1. This is a common enough kind of bug to put in code that I should have thought of it earlier (like when I was writing the book). The solution is not to use filter_var() straight up as the condition, but rather compare its output to FALSE: $qty = (filter_var($qty, FILTER_VALIDATE_INT, array('min_range' => 0)) !== false) ? $qty : 1; And the bug is gone. This change needs to be made in cart.php and wishlist.php. And one would want to use the !== false construct whenever the basis of a condition could return a valid value that PHP would interpret as FALSE (i.e., you need to do this in conditionals when there's a distinction between FALSE-ish values such as 0 and actual FALSE). Apologies again for the confusion and thanks for pointing it out.
  16. Exactly, except not. You create one table for the cars and one table of images. You don't put FK's of the images in the cars table but rather put a FK of the car associated with each image in the images table. This is a totally logical, common, and appropriate solution.
  17. Sorry, I can't recommend a host, because I would never, in a million years, acquire Windows hosting! But Paul has a good point, too, or you could use Boot Camp to install Windows on your Mac.
  18. Well, the easiest solution may just be to purchase cheap Windows hosting for a couple of months. Get one with PHP and MS SQL Server and it may only set you back $50 for 2-4 months, then you can drop it.
  19. You're welcome. And I don't think 8 constants is a lot on a big, complicated site. More important are the benefits using constants will bring. Good luck!
  20. Although, as HartleySan said, it's best to use a single query when you can, you can't always. In those situations, multiple queries are fine (in fact, the only option).
  21. Well, using a Mac to connect to an MS SQL Server is a fairly unique idea. I've never done it myself. It doesn't look like MAMP has ODBC built in, which means to get ODBC support on MAMP, you'll need to rebuild PHP. This is not for the faint of heart, so using a purchased option may be easier. That being said, you answered the question about the hosting. Are you trying to connect from your Mac to MS SQL or will your hosted site connect to MS SQL? Or are you saying your shared hosting is on a Mac?
  22. First, excellent work so far. Second, to select the chosen year, you'll need to make the select menu part of a separate form that gets submitted to another page. That's the easy way, at least.
  23. Paul may not have been looking at the book (I suspect he doesn't have it). Just take the code he provided and replace uses of $_POST with $_COOKIE and you should be fine.
×
×
  • Create New...