Jump to content
Larry Ullman's Book Forums

Bill

Members
  • Posts

    45
  • Joined

  • Last visited

  • Days Won

    1

Bill last won the day on September 27 2012

Bill had the most liked content!

Recent Profile Visitors

53526 profile views

Bill's Achievements

Newbie

Newbie (1/14)

1

Reputation

  1. Sorting appears to be a problem with early browsers but with use of function x-y problem has been resolved with modern browsers. Click on link for more detailed info on numbers.sort() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort?redirectlocale=en-US&redirectslug=JavaScript%2FReference%2FGlobal_Objects%2FArray%2Fsort
  2. It's a typing error! Rafal says regarding errata on this webstie that on Page 247: var numbers = [1, 4, 3, 2]; numbers.sort(); // 4, 1, 3, 2 "For me it looks the better example will be [1, 14, 3, 2] and in old browsers the result will be 1, 14, 2, 3." See link: http://www.larryullman.com/books/modern-javascript-develop-and-design/errata/comment-page-1/
  3. I have been able to figure out how to get multiple checkboxes to work. After spending a couple of weeks studying similar programs from example 2, I was surprised that it only took a few minutes to do in terms of coding at the keyboard and not one error message! Parts of the code from the add_inventory script in admin section and cart.php only required small changes. However, it never occurred to me that ecommerce sites only use one item as part of payment process. After searching online for a solution I noticed one fellow said that a website is “flawed” if you cannot select more than one item. This information was in the search results and I did not click on the link. Anyway, I am not an expert here. I am only designing a non-ecommerce program for my own purposes and thus these multiple checkboxes are not part of a payment gateway at all. What I have been developing is a food program where I can select certain items from a list of categories and move them to another list like cart. The user interface is now more efficient and effortless as many products can be selected on one page to view, whereas previously this required many clicks. So thanks again as your instructions were easy to implement Larry.
  4. I think those tables will populate after providing appropriate merchant information such as your login id and transaction key. Your book should explain how to set up payment gateway and how to fully test the site using credit card details. This is how 1st edition takes care of payment process. As I do not have 2nd edition only the earlier 1st edition, I am unable to provide clarity as to how you can do it! Sorry.
  5. Try to ensure program is connecting to database as a lot of problems are related to this. .This may not be relevant but are you creating your own reg script or is the code you are using direct from downloaded code from Larry's website?
  6. It could go in the mysql statement of the script. I don't know for sure as I have the book with stored procedures.
  7. Hi all! My goal is to enhance the design of the sales program to enable the selection of many items or just one item that can be moved to the shopping cart using checkboxes. Have searched this site and on the net to solve problem in conjuction with studing lines of code in various programs listed in the book to gain clearer understanding.of problem. Here is list_sales.html with addition of checkbox code line. <?php // This page is included by sales.php. // This page displays the available sale products. // This page will make use of the query result $r. // The query returns an array of: description, image, sku, name, and stock. // Added later in Chapter 8: include ('./includes/product_functions.inc.php'); ?> <!-- box begin --> <div class="box alt"> <div class="left-top-corner"> <div class="right-top-corner"> <div class="border-top"></div> </div> </div> <div class="border-left"> <div class="border-right"> <div class="inner"> <h2>Current Sale Items</h2> <form action="http://localhost/larryullman/Sites/ecom_book/ex2.2/html/sales.php" method="post" accept-charset="utf-8"> <?php // Loop through each item: while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { echo '<h3 id="' . $row['sku'] . '">' . $row['category'] . '::' . $row['name'] .'</h3> <div class="img-box"> <p><img alt="' . $row['name'] . '" src="http://localhost/larryullman/Sites/ecom_book/ex2.2/html/products/' . $row['image'] . '" />' . $row['description'] . '<br />' . get_price('goodies', $row['price'], $row['sale_price']) . ' <strong>Availability:</strong> ' . get_stock_status($row['stock']) . '</p> <p><a href="http://localhost/larryullman/Sites/ecom_book/ex2.2/html/cart.php?sku=' . $row['sku'] . '&action=add" class="button">Add to Cart</a></p> <td align="left"><input type="checkbox" name="item['.$row['sku'].']" id="item[' . $row['sku'] . ']" size="5" class="button" /> </td> </div>'; } ?> <div class="field"><input type="submit" value="Add Products" class="button" /></div> </fieldset> </form> </div> </div> </div> <div class="left-bot-corner"> <div class="right-bot-corner"> <div class="border-bot"></div> </div> </div> </div> <!-- box end --> </div> </div> </div> <div class="left-bot-corner"> <div class="right-bot-corner"> <div class="border-bot"></div> </div> </div> </div> <!-- box end --> And here is sale.php from from with inclusion of a for loop. <?php // This file is the sales page. // It lists every sales item. // This script is begun in Chapter 8. // Require the configuration before any PHP code: require ('./includes/config.inc.php'); // Include the header file: $page_title = 'Sale Items'; include ('./includes/header.html'); // Require the database connection: require (MYSQL); // Invoke the stored procedure: $r = mysqli_query ($dbc, 'CALL select_sale_items(true)'); if (mysqli_num_rows($r) > 0) { include ('./views/list_sales.html'); } else { include ('./views/noproducts.html'); } // run through items added to cart: if (isset($_POST['items']) && is_array($_POST['items'])) { // Loop through each submitted value: foreach ($_POST['items'] as $sku => $qty) { // Validate the added quantity: if (filter_var($qty, FILTER_VALIDATE_INT, array('min_range' => 1))) { // Parse the SKU: list($type, $id) = parse_sku($sku); $items = (empty($_POST['items'][$sku]))? NULL: $_POST['items']['$sku']; } } // End of IF. } // End of FOREACH. // Include the footer file: include ('./includes/footer.html'); ?> Thank you in advance! Windows 7 Xampp 1.8.3 php version 5.5.11 phpMyAdmin 4.1.12 Mysql Server 5.6
  8. Hi - sorry for the delayed response but I have made a bit of progress. I have managed to get the dropdown selection list to appear in cart.html but I can't select and pass each size variable to the url: $sizes = array(0.25, 0.50, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0); $size = 'size[' . $row['sku'] . ']'; echo '<td align="center"><select name="size[' . $row['sku'] . ']" value="size">'; echo '<option value="size[' . $row['size'] . ']">Choose</option>'; foreach ($sizes as $id => $size) { echo '<option value="$id ">' ; if ($size == $id) echo ' selected="selected"'; echo "$size</option>" ; } echo '</select>'; And here is the part that transfers the size variable: <td align="center" width="26%"><p><a href="http://localhost/larryullman/Sites/ecom_book/ex2.2/html/cart.php?sku=' . $row['sku'] . '&action=move&qty='.$row['quantity']. '&action=move&size=' . $size . '">Add to Cart</a></p></td> The only problem is that the last value in the array, that is, 2.0 is only passed. Nevertheless, size=2 does appear in the url but no other variable in the array can be selected or sent via the url? Thanks for your suggestions!
  9. I have been able to echo the $uid variable in the coffee cart.php script when the stored procedure is being called. However, if the mysql query get_shopping_cart_contents is running in a non-stored procedure environment, an error message saying "your shopping cart is empty!" occurs. This error message appears to suggest that the syntax of the mysql query in a non-stored procedure environment is at fault but I am not sure that is the case. Here is the error message: An error occurred in script 'C:\xampp\htdocs\larryullman\Sites\ecom_book\ex2\html\cart.php' on line 117: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given Array ( [0] => Array ( [function] => my_error_handler [args] => Array ( [0] => 2 [1] => mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given [2] => C:\xampp\htdocs\larryullman\Sites\ecom_book\ex2\html\cart.php [3] => 117 [4] => Array ( [GLOBALS] => Array *RECURSION* [_POST] => Array ( ) [_GET] => Array ( ) [_COOKIE] => Array ( [sESSION] => 762d4f78b298d60a1d5279e67a5db64e [__atuvc] => 1|27 ) [_FILES] => Array ( ) [_ENV] => Array ( ) [_REQUEST] => Array ( ) [_SERVER] => Array ( [MIBDIRS] => C:/xampp/php/extras/mibs [MYSQL_HOME] => \xampp\mysql\bin [OPENSSL_CONF] => C:/xampp/apache/bin/openssl.cnf [php_PEAR_SYSCONF_DIR] => \xampp\php [phpRC] => \xampp\php [TMP] => \xampp\tmp [HTTP_ACCEPT] => text/html, application/xhtml+xml, */* [HTTP_REFERER] => http://localhost/larryullman/Sites/ecom_book/ex2/html/cart.php [HTTP_ACCEPT_LANGUAGE] => en-AU [HTTP_USER_AGENT] => Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0) [HTTP_UA_CPU] => AMD64 [HTTP_ACCEPT_ENCODING] => gzip, deflate [HTTP_HOST] => localhost [HTTP_CONNECTION] => Keep-Alive [HTTP_COOKIE] => SESSION=762d4f78b298d60a1d5279e67a5db64e; __atuvc=1%7C27 [PATH] => C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;c:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;c:\Program Files (x86)\Common Files\Roxio Shared\OEM\12.0\DLLShared\;c:\Program Files (x86)\Roxio\OEM\AudioCore\;C:\Program Files (x86)\Windows Live\Shared; [systemRoot] => C:\windows [COMSPEC] => C:\windows\system32\cmd.exe [PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC [WINDIR] => C:\windows [sERVER_SIGNATURE] => Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1 Server at localhost Port 80 [sERVER_SOFTWARE] => Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1 [sERVER_NAME] => localhost [sERVER_ADDR] => ::1 [sERVER_PORT] => 80 [REMOTE_ADDR] => ::1 [DOCUMENT_ROOT] => C:/xampp/htdocs [sERVER_ADMIN] => postmaster@localhost [sCRIPT_FILENAME] => C:/xampp/htdocs/larryullman/Sites/ecom_book/ex2/html/cart.php [REMOTE_PORT] => 50470 [GATEWAY_INTERFACE] => CGI/1.1 [sERVER_PROTOCOL] => HTTP/1.1 [REQUEST_METHOD] => GET [QUERY_STRING] => [REQUEST_URI] => /larryullman/Sites/ecom_book/ex2/html/cart.php [sCRIPT_NAME] => /larryullman/Sites/ecom_book/ex2/html/cart.php [php_SELF] => /larryullman/Sites/ecom_book/ex2/html/cart.php [REQUEST_TIME] => 1355634766 ) [live] => [contact_email] => [uid] => 762d4f78b298d60a1d5279e67a5db64e [page_title] => Coffee - Your Shopping Cart [dbc] => mysqli Object ( [affected_rows] => -1 [client_info] => mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $ [client_version] => 50008 [connect_errno] => 0 [connect_error] => [errno] => 1064 [error] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0' at line 1 [field_count] => 0 [host_info] => localhost via TCP/IP [info] => [insert_id] => 0 [server_info] => 5.5.16 [server_version] => 50516 [sqlstate] => 42000 [protocol_version] => 10 [thread_id] => 70 [warning_count] => 0 ) [r] => ) ) ) [1] => Array ( [file] => C:\xampp\htdocs\larryullman\Sites\ecom_book\ex2\html\cart.php [line] => 117 [function] => mysqli_num_rows [args] => Array ( [0] => ) ) ) Your Shopping Cart Your shopping cart is currently empty.
  10. Yes, that's correct...It returns rows if the cart session_id is hardcoded in phpmyadmin but not with the variable.
  11. Well, here are my latest findings. The query below works in phpmyadmin when the user_session_id is used instead of the $uid variable:- SELECT CONCAT("O", ncp.id) AS sku, c.quantity, ncc.category, ncp.name, ncp.price, ncp.stock, ncp.energy, ncp.protein, ncp.fat, sales.price AS sale_price FROM carts AS c INNER JOIN non_coffee_products AS ncp ON c.product_id=ncp.id INNER JOIN non_coffee_categories AS ncc ON ncc.id=ncp.non_coffee_category_id LEFT OUTER JOIN sales ON (sales.product_id=ncp.id AND sales.product_type="other" AND ((NOW() BETWEEN sales.start_date AND sales.end_date) OR (NOW() > sales.start_date AND sales.end_date IS NULL)) ) WHERE c.product_type="other" AND c.user_session_id="871a5d394995b479efd5a2e9bfce249c" After trying virtually every variation for the variable "$uid" such as ".$uid." the query run using phpmyadmin doesn't show any rows listed. I have noticed that the stored procedure get_shopping_cart_contents defines uid as a char so maybe it has to be defined either in the query or the code of cart.php.
  12. I think I had a similar problem but it was a long time ago. The query to most popular pages could be the source of the error. Try replacing this query with what you have in your code in index.php q = "SELECT COUNT(history.id) AS num, pages.id, pages.title FROM pages, history WHERE pages.id=history.page_id AND history.type='page' GROUP BY (history.page_id) ORDER BY num DESC LIMIT 10"; Cheers
  13. Here is the query with double quotes removed but still generates parse errors: $r = mysqli_query($dbc, 'SELECT CONCAT("O", ncp.id) AS sku, c.quantity, ncc.category, ncp.name, ncp.price, ncp.stock, ncp.energy, ncp.protein, ncp.fat, sales.price AS sale_price FROM carts AS c INNER JOIN non_coffee_products AS ncp ON c.product_id=ncp.id INNER JOIN non_coffee_categories AS ncc ON ncc.id=ncp.non_coffee_category_id LEFT OUTER JOIN sales ON (sales.product_id=ncp.id AND sales.product_type="other" AND ((NOW() BETWEEN sales.start_date AND sales.end_date) OR (NOW() > sales.start_date AND sales.end_date IS NULL)) ) WHERE c.product_type="other" AND c.user_session_id="$uid" UNION SELECT CONCAT("C", sc.id), c.quantity, gc.category, CONCAT_WS(" - ", s.size), sc.price, sc.stock, sc.energy, sc.protein, sc.fat, sales.price FROM carts AS c INNER JOIN specific_coffees AS sc ON c.product_id=sc.id INNER JOIN sizes AS s ON s.id=sc.size_id INNER JOIN general_coffees AS gc ON gc.id=sc.general_coffee_id LEFT OUTER JOIN sales ON (sales.product_id=sc.id AND sales.product_type="coffee" AND ((NOW() BETWEEN sales.start_date AND sales.end_date) OR (NOW() > sales.start_date AND sales.end_date IS NULL)) ) WHERE c.product_type="coffee" AND c.user_session_id="$uid"'); I don't know why it works as a stored procedure but not as a non-procedural statement. Perhaps it's because of syntax errors! Cheers
  14. I think I know what to do now! The solution requires another procedure called call_select_sizes to show the various sizes in the pulldown list and another while loop withingin the existing cart.php loop. Two while loops could be impractical from a design perspective!
×
×
  • Create New...