Jump to content
Larry Ullman's Book Forums

All Activity

This stream auto-updates

  1. Last week
  2. Hi Larry, Hope you are well. Qu 1: wanted to know, how would I change the price of a product based on the different sizes? So if a customer goes to the product details page for a product, it would have all the different size options. The product would have a default option with a default size. If the customer clicked on the small size the price would change according to that size. Similarly a price change for sizes medium and large. I could then add that size and price to the shopping cart. Qu 2: And lastly how would I allow the user to select different colors for the product, and be able to add that color product to the database? I could then add that color for that product to the shopping cart Thanks in advance
  3. Earlier
  4. I'm a college professor and I'd like to use your PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition) book in my course. Can you provide PPT Slides? Do you have any sample tests or homework assignments?
  5. You've already done all the hard work. Kudos! You have the values you need, as an associative array. All you need to do now is pop those values into an INSERT query, something like $arr = json_decode($json, true); if (!empty($arr['isbn'])) { // Basic validation that data was returned... INSERT INTO books (ISBN, title) VALUES ('{$arr['isbn']}', '{$arr['title']}'); Although it'd be best if you use prepared statements or somehow sanitized the values before using them in the query.
  6. I'm trying to help the Friends of My Local Library with a project to make it easier to deal with donated books. There is a program that will take and either buy used books or recycle them. We have to put together a list of books with specific information and send it to the program sponsor. Right now it has our members of the "friends" hand entering the information into an Excel spreadsheet and sending it to the program sponsor. I've figured out how to get the information from the ISBNdb.com using "curl". It comes as a json array that looks like this when I search using an input form like this: <form action="add_bt_book20h.php" method="get"> ISBN: <input type="text" name="isbn"><br> <br> <input type="submit"> </form> I get back this information: ************************************ {"book":{"publisher":"Peachpit Press", ","language":"en_US","format":"Paperback","image":"https://images.isbndb.com/covers/60/15/9780321376015.jpg","title_long":"PHP 5 Advanced: Visual QuickPro Guide","edition":"2nd","dimensions":"Height: 9 Inches, Length: 7 Inches, Weight: 2.09880073424 Pounds, Width: 1.151 Inches","pages":608,"date_published":"2007-03-15T00:00:01Z","subjects":["Computers & the Internet","Internet"],"authors":["Ullman, Larry"],"title":"PHP 5 Advanced: Visual QuickPro Guide","isbn13":"9780321376015","msrp":"39.99","binding":"Paperback","related":{"ePub":"0132712288"},"isbn":"0321376013","other_isbns":[{"isbn":"9780132712286","binding":"print"}]}} *********************************** Yes, that's Larry's PHP5 Advanced book. for space reasons I pulled "synopsis" and it's value out I can then get it to look like what follows by trimming stuff, assigning a $json = $book and then using JSON decode and a loop to look like the following: ************************************************ publisher=>Peachpit Press language=>en_US format=>Paperback image=>https://images.isbndb.com/covers/60/15/9780321376015.jpg title_long=>PHP 5 Advanced: Visual QuickPro Guide edition=>2nd dimensions=>Height: 9 Inches, Length: 7 Inches, Weight: 2.09880073424 Pounds, Width: 1.151 Inches pages=>608 date_published=>2007-03-15T00:00:01Z subjects=>Array authors=>Array title=>PHP 5 Advanced: Visual QuickPro Guide isbn13=>9780321376015 msrp=>39.99 binding=>Paperback related=>Array isbn=>0321376013 other_isbns=>Array ***************************** I've also built a database in Mysql to take this all in with the goal of then selecting just the keys/values that we need to send to the program sponsor. My question is how do I send( insert ) that in to my database. I've built forms to collect and insert info into databases, but how do I upload this stuff or can i somehow plug it automatically into a form(I've built one to manually do this and it works) Any solutions would be most appreciated. dave (kn6koo) Here's what I've done so far to get to where I am. Not pretty, but I'm not sure what I have that would work. **************************** <?php $url = "https://api2.isbndb.com/book/" . $_GET["isbn"] .""; $curl = curl_init($url); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $headers = array( "accept: application/json", "Authorization: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", ); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); //for debug only! curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $resp = curl_exec($curl); curl_close($curl); $book = $resp; echo $book . '<br><br>'; $book2 = ltrim($book, '{"book":' ); echo $book2 . "<br>"; $book3 = rtrim($book2,"}"); $str4='{"'; $str5= '}'; $book5 = ($str4 . "" . $book3 . "" .$str5) ; echo($str4 . "" . $book3 . "" .$str5) ; '<br><br>'; '<br><br>'; echo $book5; '<br><br>'; '<br><br>'; ?> <br /> <br><br> <br><br> <br><br> <?php // Assign JSON encoded string to a PHP variable $json = $book5 ; // Decode JSON data to PHP associative array $arr = json_decode($json, true); // Loop through the associative array foreach($arr as $key=>$value){ echo $key . "=>" . $value . "<br>"; } echo "<hr>"; // Decode JSON data to PHP object $obj = json_decode($json); // Loop through the object foreach($obj as $key=>$value){ echo $key . "=>" . $value . "<br>"; } ?> </body> ******************************** Here's the output of all that: ******************************* {"book":{"publisher":"Peachpit Press","synopsys":" PHP is currently one of the most popular server-side, HTML-embedded scripting language on the Web. It's specifically designed for Web site creation and is frequently being used to replace the functionality created by Perl to write CGI scripts. PHP's popularity and easier-to-learn appeal has spawned a new breed of programmer, those who are only familiar with and only use PHP. Sharpen your PHP skills with the fully revised and updated, PHP 5 Advanced for the World Wide Web: Visual QuickPro Guide! Filled with fifteen chapters of step-by-step content and written by best-selling author and PHP programmer, Larry Ullman, this guide teaches specific topics in direct, focused segments, shows how PHP is used in real-world applications, features popular and most-asked-about scripts, and details those technologies that will be more important in the future. You'll learn about object-oriented programming, PHP interactions with a server, ","language":"en_US","format":"Paperback","image":"https://images.isbndb.com/covers/60/15/9780321376015.jpg","title_long":"PHP 5 Advanced: Visual QuickPro Guide","edition":"2nd","dimensions":"Height: 9 Inches, Length: 7 Inches, Weight: 2.09880073424 Pounds, Width: 1.151 Inches","pages":608,"date_published":"2007-03-15T00:00:01Z","subjects":["Computers & the Internet","Internet"],"authors":["Ullman, Larry"],"title":"PHP 5 Advanced: Visual QuickPro Guide","isbn13":"9780321376015","msrp":"39.99","binding":"Paperback","related":{"ePub":"0132712288"},"isbn":"0321376013","other_isbns":[{"isbn":"9780132712286","binding":"print"}]}} publisher":"Peachpit Press","synopsys":" PHP is currently one of the most popular server-side, HTML-embedded scripting language on the Web. It's specifically designed for Web site creation and is frequently being used to replace the functionality created by Perl to write CGI scripts. PHP's popularity and easier-to-learn appeal has spawned a new breed of programmer, those who are only familiar with and only use PHP. Sharpen your PHP skills with the fully revised and updated, PHP 5 Advanced for the World Wide Web: Visual QuickPro Guide! Filled with fifteen chapters of step-by-step content and written by best-selling author and PHP programmer, Larry Ullman, this guide teaches specific topics in direct, focused segments, shows how PHP is used in real-world applications, features popular and most-asked-about scripts, and details those technologies that will be more important in the future. You'll learn about object-oriented programming, PHP interactions with a server, ","language":"en_US","format":"Paperback","image":"https://images.isbndb.com/covers/60/15/9780321376015.jpg","title_long":"PHP 5 Advanced: Visual QuickPro Guide","edition":"2nd","dimensions":"Height: 9 Inches, Length: 7 Inches, Weight: 2.09880073424 Pounds, Width: 1.151 Inches","pages":608,"date_published":"2007-03-15T00:00:01Z","subjects":["Computers & the Internet","Internet"],"authors":["Ullman, Larry"],"title":"PHP 5 Advanced: Visual QuickPro Guide","isbn13":"9780321376015","msrp":"39.99","binding":"Paperback","related":{"ePub":"0132712288"},"isbn":"0321376013","other_isbns":[{"isbn":"9780132712286","binding":"print"}]}} {"publisher":"Peachpit Press","synopsys":" PHP is currently one of the most popular server-side, HTML-embedded scripting language on the Web. It's specifically designed for Web site creation and is frequently being used to replace the functionality created by Perl to write CGI scripts. PHP's popularity and easier-to-learn appeal has spawned a new breed of programmer, those who are only familiar with and only use PHP. Sharpen your PHP skills with the fully revised and updated, PHP 5 Advanced for the World Wide Web: Visual QuickPro Guide! Filled with fifteen chapters of step-by-step content and written by best-selling author and PHP programmer, Larry Ullman, this guide teaches specific topics in direct, focused segments, shows how PHP is used in real-world applications, features popular and most-asked-about scripts, and details those technologies that will be more important in the future. You'll learn about object-oriented programming, PHP interactions with a server, ","language":"en_US","format":"Paperback","image":"https://images.isbndb.com/covers/60/15/9780321376015.jpg","title_long":"PHP 5 Advanced: Visual QuickPro Guide","edition":"2nd","dimensions":"Height: 9 Inches, Length: 7 Inches, Weight: 2.09880073424 Pounds, Width: 1.151 Inches","pages":608,"date_published":"2007-03-15T00:00:01Z","subjects":["Computers & the Internet","Internet"],"authors":["Ullman, Larry"],"title":"PHP 5 Advanced: Visual QuickPro Guide","isbn13":"9780321376015","msrp":"39.99","binding":"Paperback","related":{"ePub":"0132712288"},"isbn":"0321376013","other_isbns":[{"isbn":"9780132712286","binding":"print"}]}{"publisher":"Peachpit Press","synopsys":" PHP is currently one of the most popular server-side, HTML-embedded scripting language on the Web. It's specifically designed for Web site creation and is frequently being used to replace the functionality created by Perl to write CGI scripts. PHP's popularity and easier-to-learn appeal has spawned a new breed of programmer, those who are only familiar with and only use PHP. Sharpen your PHP skills with the fully revised and updated, PHP 5 Advanced for the World Wide Web: Visual QuickPro Guide! Filled with fifteen chapters of step-by-step content and written by best-selling author and PHP programmer, Larry Ullman, this guide teaches specific topics in direct, focused segments, shows how PHP is used in real-world applications, features popular and most-asked-about scripts, and details those technologies that will be more important in the future. You'll learn about object-oriented programming, PHP interactions with a server, ","language":"en_US","format":"Paperback","image":"https://images.isbndb.com/covers/60/15/9780321376015.jpg","title_long":"PHP 5 Advanced: Visual QuickPro Guide","edition":"2nd","dimensions":"Height: 9 Inches, Length: 7 Inches, Weight: 2.09880073424 Pounds, Width: 1.151 Inches","pages":608,"date_published":"2007-03-15T00:00:01Z","subjects":["Computers & the Internet","Internet"],"authors":["Ullman, Larry"],"title":"PHP 5 Advanced: Visual QuickPro Guide","isbn13":"9780321376015","msrp":"39.99","binding":"Paperback","related":{"ePub":"0132712288"},"isbn":"0321376013","other_isbns":[{"isbn":"9780132712286","binding":"print"}]} publisher=>Peachpit Press synopsys=> PHP is currently one of the most popular server-side, HTML-embedded scripting language on the Web. It's specifically designed for Web site creation and is frequently being used to replace the functionality created by Perl to write CGI scripts. PHP's popularity and easier-to-learn appeal has spawned a new breed of programmer, those who are only familiar with and only use PHP. Sharpen your PHP skills with the fully revised and updated, PHP 5 Advanced for the World Wide Web: Visual QuickPro Guide! Filled with fifteen chapters of step-by-step content and written by best-selling author and PHP programmer, Larry Ullman, this guide teaches specific topics in direct, focused segments, shows how PHP is used in real-world applications, features popular and most-asked-about scripts, and details those technologies that will be more important in the future. You'll learn about object-oriented programming, PHP interactions with a server, language=>en_US format=>Paperback image=>https://images.isbndb.com/covers/60/15/9780321376015.jpg title_long=>PHP 5 Advanced: Visual QuickPro Guide edition=>2nd dimensions=>Height: 9 Inches, Length: 7 Inches, Weight: 2.09880073424 Pounds, Width: 1.151 Inches pages=>608 date_published=>2007-03-15T00:00:01Z subjects=>Array authors=>Array title=>PHP 5 Advanced: Visual QuickPro Guide isbn13=>9780321376015 msrp=>39.99 binding=>Paperback related=>Array isbn=>0321376013 other_isbns=>Array publisher=>Peachpit Press synopsys=> PHP is currently one of the most popular server-side, HTML-embedded scripting language on the Web. It's specifically designed for Web site creation and is frequently being used to replace the functionality created by Perl to write CGI scripts. PHP's popularity and easier-to-learn appeal has spawned a new breed of programmer, those who are only familiar with and only use PHP. Sharpen your PHP skills with the fully revised and updated, PHP 5 Advanced for the World Wide Web: Visual QuickPro Guide! Filled with fifteen chapters of step-by-step content and written by best-selling author and PHP programmer, Larry Ullman, this guide teaches specific topics in direct, focused segments, shows how PHP is used in real-world applications, features popular and most-asked-about scripts, and details those technologies that will be more important in the future. You'll learn about object-oriented programming, PHP interactions with a server, language=>en_US format=>Paperback image=>https://images.isbndb.com/covers/60/15/9780321376015.jpg title_long=>PHP 5 Advanced: Visual QuickPro Guide edition=>2nd dimensions=>Height: 9 Inches, Length: 7 Inches, Weight: 2.09880073424 Pounds, Width: 1.151 Inches pages=>608 date_published=>2007-03-15T00:00:01Z subjects=>Array authors=>Array title=>PHP 5 Advanced: Visual QuickPro Guide isbn13=>9780321376015 msrp=>39.99 binding=>Paperback ************************************************ Thanks in advance
  7. You can use the arrayObject.filter() method to remove elements from an array at specific index in JavaScript. var rValue = 'three' var arrayItems = ['one', 'two', 'three', 'four', 'five', 'six'] arrayItems = arrayItems.filter(item => item !== rValue) console.log(arrayItems)
  8. The override identifier asks the compiler to display error messages when these blunders are made. In the absence of these error messages, even though the program might compile, there’s a possibility that the virtual function does not get overridden like the case of using Incorrect function names, Non-matching function parameters, No function is defined as virtual in the parent class there many other use case of override identifiers in virtual functions most of them are listed here in this Scaler article, I’d strongly recommend going through it.
  9. How are override identifiers helping while declaring member functions of the parent classes using virtual functions?
  10. If you're concerned about a fake ID scenario AND such a query not affecting any rows is cause to stop execution of the code, you could run a SELECT query using the ID first to validate that it's real before running the UPDATE. That being said, doing all that seems to me like adding extra overhead to "solve" a problem that's not really a problem. The UPDATE query, like on a password change, should use the primary key, which is immutable, and therefore not user-provided. It's unclear how a fake ID would get into the mix.
  11. Hi Thanks for your answer. I have played with the function mysqli_query() to verify the results There are 4 main Scenarios Scenario 1 INSERT INTO (column name) VALUE ('value') WHERE something_id = id id = real id from the database (FOREIGN KEY) ; mysqli_query() = 1 (true) mysqli_affected_rows($dbc) = 1 (true) Scenario 2 INSERT INTO (column name) VALUE ('value') WHERE something_id = id ; id = fake id (not exist in the databse) mysqli_query() = 0 (false) mysqli_affected_rows($dbc) = -1 (false) Scenario 3 UPDATE TABLE table_name SET column_name = 'value' WHERE something_id = id ; id = id real id from the database (FOREIGN KEY) (Changing value in the table) mysqli_query() = 1 (true) mysqli_affected_rows($dbc) = 1 (true) (Don't changing value in the table) mysqli_query() = 1 (true) mysqli_affected_rows($dbc) = 0 (false) Scenario 4 UPDATE TABLE table_name SET column_name = 'value' WHERE something_id = id ; id = fake id (not exist in the databse) mysqli_query() = 1 (true) mysqli_affected_rows($dbc) = 0 (false) So after all that my claim is that mysli_query() return true although when the id isn't real, so it is not a good indication since if somehow my id value isn't correct (or any other problem i didn't tested yet) I won't be able to know that and stop the execution of the code after this point. Sorry about the length and I do understand it's already out of the book scope I just tested the function and thought you may be interested in the results. if you have solution I'll be glad to hear from you Thanks ahead Yuval
  12. Thanks so much for the nice words! I really appreciate it. This is an excellent question! What you can do is just use mysqli_query() as the conditional. The function returns a false value if it didn't run (i.e., there's an error), which is a different thing than the query running but not affecting a change. https://www.php.net/manual/en/mysqli.query.php
  13. First of all Your Books are the world for me. valuable and reliable content Thanks. In chapter 9 as we are doing update for the password I adjusted a little bit the code and I come up on an issue I can't solve. If I'm inserting information to the inputs with similar content to the one already exist in the database table mysqli_affected_rows($dbc) return 0 , So how could I differentiate between an error in the update to the situation when just any change didn't take place in the process of the Update?
  14. Thanks for your interest and sorry for the delayed reply. Right now there's no plan to update the PHP Advanced book. I've not even spoken with the publisher about it. Thanks again, though, for asking!
  15. Just wanted to know, if there is going to be a new edition of this book in the near future and if there is, when will this book be out, please let me know. Best Regards, Fred
  16. Hi Larry, Regarding your spam blocker, of course, I have been using it. However, I was still getting emails from automated spam producers, bots or whatever, so I thought I would share this little routine with you. It simply checks to see if there is a human at the other end (who can add!!) and I now receive NO spam at all. All I do is ask the customer to add two numbers. I put these as numerics, but one could create an array with 1 = One, 2 = two etc etc. I'll leave out all of the extraneous code. Header etc etc <?php $check = $_POST['check']; //Getting answer from customer of the addition. $result2 = $_POST['checking']; //Getting answer from the addition by the server. //if then loops etc, with all of the questions etc.... //...after spam scrubber: if($check == $result2) { //Send the email to me and thank customer } else { echo '<h2 style = "font-family: Arial, Verdana; font-size: 20px; font-weight: bold; background-color: #ffff99;">It seems that your arithmetic is erroneous. Please try again.'; //Make the customer do the sum again. } ?> //Start form action..... Check:<br /> //Or you could write more informative text for the customer. <?php $random1 = RAND(1, 9); //Invent an integer between 1 and 9. $random2 = RAND(1, 9); //Ditto. $result1 = $random1 + $random2; //Do the math!! echo 'What is ' . $random1 . ' plus ' . $random2 . '? <input type="text" name="check" size="3"/><input type = "hidden" name = "checking" value = "' . $result1 . '" /><br /><br />' ; //Ask the customer the question - the answer to the addition. Also send the server's answer ($result1). ?> <input type="submit" value="Send" ><input type="hidden" name ="Secure" value = "ejeewq8"> <input type="reset" value="Clear"> <input type = "hidden" name = "submitted" value = "submitted"> //Send it. <br /><br /> I hope that you find it interesting. Regards Max
  17. If you just google "xampp mail server windows" you'll find plenty of tutorials on the subject. (I don't have XAMPP on Windows, so I don't know off the top of my head.)
  18. Thanks larry since i do not have local mail server, can i use php.net mail server ? [mail function] ; For Win32 only. ; http://php.net/smtp SMTP=localhost ; http://php.net/smtp-port smtp_port=25
  19. From there error messages, you have two issues to resolve. The first is you haven't configured a local mail server. The second is your error handling script still references the $e_vars variable, which it no longer has defined as an argument.
  20. Hi Larry, Thanks for your responding. I have removed the last parameter from my_error_handler() when i run again http://127.0.0.1/phpmysql4_scripts/ch18/html/register.php User Registration An error occurred in script 'D:\xampp\htdocs\phpmysql4_scripts\ch18\html\register.php' on line 70: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() Date/Time: 9-17-2021 23:23:14 Warning: Undefined variable $e_vars in D:\xampp\htdocs\phpmysql4_scripts\ch18\html\includes\config.inc.php on line 54 #0 my_error_handler(2, mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set(), D:\xampp\htdocs\phpmysql4_scripts\ch18\html\register.php, 70) #1 mail(wongkinping@chinalifeagt.com.hk, Registration Confirmation, Thank you for registering at . To activate your account, please click on this link: http://127.0.0.1/phpmysql4_scripts/ch18/html/activate.php?x=wongkinping%40chinalifeagt.com.hk&y=a331f2faab5825188d23eca77974f18f, From: admin@sitename.com) called at [D:\xampp\htdocs\phpmysql4_scripts\ch18\html\register.php:70] Thank you for registering! A confirmation email has been sent to your address. Please click on the link in that email in order to activate your account. sorry for any simple question, but I am new to PHP. Thanks Andrew
  21. There are two issues here. One is that there's an error going on in the script. The second is the error handling isn't working properly. For the latter, you don't mention what version of PHP you're using, but I expect the warning in the box applies: https://www.php.net/manual/en/function.set-error-handler.php Remove the last parameter from the my_error_handler() definition, as well as the use of that $e_vars variable within it. Once you fix that, you should properly see the actual error that's happening on the page.
  22. User Registration Fatal error: Uncaught ArgumentCountError: Too few arguments to function my_error_handler(), 4 passed and exactly 5 expected in D:\xampp\htdocs\phpmysql4_scripts\ch18\html\includes\config.inc.php:38 Stack trace: #0 [internal function]: my_error_handler(2, 'mail(): Failed ...', 'D:\\xampp\\htdocs...', 70) #1 D:\xampp\htdocs\phpmysql4_scripts\ch18\html\register.php(70): mail('trandrew8@gmail...', 'Registration Co...', 'Thank you for r...', 'From: admin@sit...') #2 {main} thrown in D:\xampp\htdocs\phpmysql4_scripts\ch18\html\includes\config.inc.php on line 38
  23. http://127.0.0.1/phpmysql4_scripts/ch18/html/register.php User Registration Fatal error: Uncaught ArgumentCountError: Too few arguments to function my_error_handler(), 4 passed and exactly 5 expected in D:\xampp\htdocs\phpmysql4_scripts\ch18\html\includes\config.inc.php:38 Stack trace: #0 D:\xampp\htdocs\phpmysql4_scripts\ch18\html\register.php(10): my_error_handler(2, 'require(../../m...', 'D:\\xampp\\htdocs...', 10) #1 D:\xampp\htdocs\phpmysql4_scripts\ch18\html\register.php(10): require() #2 {main} thrown in D:\xampp\htdocs\phpmysql4_scripts\ch18\html\includes\config.inc.php on line 38
  1. Load more activity
×
×
  • Create New...