Larry
Administrators-
Posts
5413 -
Joined
-
Last visited
-
Days Won
155
Everything posted by Larry
-
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.
-
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.
-
Readfile Vs Fopen
Larry replied to Hope4You's topic in PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
Perhaps there are benefits to using fopen() et al. that I'm unaware of, but my inclination would be to just use readfile(). -
Ajax Questions!
Larry replied to Matt's topic in PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
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. -
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.
-
Ajax Questions!
Larry replied to Matt's topic in PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
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. -
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.
-
Problems With Ecommerce Example 2 Demo Site
Larry replied to gameface's topic in Effortless E-Commerce with PHP and MySQL
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. -
Problems With Ecommerce Example 2 Demo Site
Larry replied to gameface's topic in Effortless E-Commerce with PHP and MySQL
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. -
Data Insert In To Multiple Tables
Larry replied to nick's topic in Effortless E-Commerce with PHP and MySQL
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. -
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!
-
Data Insert In To Multiple Tables
Larry replied to nick's topic in Effortless E-Commerce with PHP and MySQL
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). -
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?
-
Question Re Exercise From Chapter 9
Larry replied to Sergiu's topic in PHP for the Web: Visual QuickStart Guide (4th Edition)
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.