Jump to content
Larry Ullman's Book Forums

Ryan R

Members
  • Posts

    63
  • Joined

  • Last visited

Everything posted by Ryan R

  1. Hi All, Thank you in advance for your help. I am having a little bit of difficulty understanding cart.php and cart.html. First of all, if you look at the line in cart.html below, you will see name="quantity[' . $row['sku'] . ']". I don't understand that quantity's variable can be sku. <td align="center"><input type="text" name="quantity[' . $row['sku'] . ']" value="' . $row['quantity'] . '" size="2" class="small" /></td> Also, if you look at down below which is from cart.php, how could $_POST['quantity'] have an array of $sku => $qty? Does it related to name="quantity[' . $row['sku'] . ']"? If so, how can you make it related to $_POST['quantity']? I don't understand that you can get the value right away just because that input's name has quantity[sku]. elseif (isset($_POST['quantity'])) { // Update quantities in the cart. // Loop through each item: foreach ($_POST['quantity'] as $sku => $qty) { // Parse the SKU: list($sp_type, $pid) = parse_sku($sku); if (isset($sp_type, $pid)) { // Determine the quantity: $qty = (filter_var($qty, FILTER_VALIDATE_INT, array('min_range' => 0)) !== false) ? $qty : 1; // Update the quantity in the cart: $r = mysqli_query($dbc, "CALL update_cart('$uid', '$sp_type', $pid, $qty)"); Thanks for your help. forgive me for the lack of understanding this book and look forward to hearing from you soon.
  2. Thanks Guys, I am currently testing it on xampp. But if I want to test transactions with credit cards, you might want to have your server, right? Or Can I still test it on xampp?
  3. Larry, I found that some hosting companies don't provide EXECUTE privileges in MySQL. Can you recommend me some good hosting companies? Thanks Ryan
  4. Thanks for your reply. My php version on the server was 5.2.17. Thanks for your info about my mysql.
  5. Larry, Thanks for your comments. I think my php version is 5 and mysql version is 5.0.91. I uncomment the line and see what is the issue. The error msg I got is "execute command denied to user 'ryandivi_012'@'localhost' for routine 'ryandivi_ecommerce2.select_categories' An error occurred in script '/home/ryandivi/public_html/shop.php' on line 33: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given Array" It looks like connection problem.. Is it? You can see it here: http://ryan.divinehosting.ca/shop.php
  6. I uncomment the debugging line. But it still tells me the same thing. The error msg is like this: "An error occurred in script '/home/ryandivi/public_html/shop.php' on line 30: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given Array" Please see below my shop.php code. ( I think uncommenting a line isn't affecting the web page as it's just a comment. As you can see my previous post above, the debugging wasn't activating as I put double slashes in front of the code.) ----------------------------------------------------------------------------------------------------------------------------- <?php // This file lists categories of products. // This script is begun in Chapter 8. // Require the configuration before any PHP code: require ('./includes/config.inc.php'); // Validate the product type... if (isset($_GET['type']) && ($_GET['type'] == 'goodies')) { $page_title = 'Our Goodies, by Category'; $sp_type = 'other'; $type = 'goodies'; } else { // Default is coffee! $page_title = 'Our Coffee Products'; $type = $sp_type = 'coffee'; } // Include the header file: include ('./includes/header.html'); // Require the database connection: require (MYSQL); // Call the stored procedure: $r = mysqli_query($dbc, "CALL select_categories('$sp_type')"); // If records were returned, include the view file: if (mysqli_num_rows($r) > 0) { include ('./views/list_categories.html'); } else { // Include the error page: include ('./views/error.html'); } // Include the footer file: include ('./includes/footer.html'); ?>
  7. Good to know.. Too bad I can't execute it. Maybe php6 and mysql5 would work?
  8. Hi All, Thank you very much for all your efforts and helps. I've got into a problem when I try to execute 'shop.php' page after putting error.html, and list_categories.html under view folder. I also put all those css and js files that I got from the download on your website to my server. When I execute shop.php file on my server, it gave this error msg 'An error occurred in script '/home/ryandivi/public_html/shop.php' on line 32: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given Array' shop.php file code is like this below: The problem line is in bold ---------------------------------------------------------------------------------------------------------------------- <?php // This file lists categories of products. // This script is begun in Chapter 8. // Require the configuration before any PHP code: require ('./includes/config.inc.php'); // Validate the product type... if (isset($_GET['type']) && ($_GET['type'] == 'goodies')) { $page_title = 'Our Goodies, by Category'; $sp_type = 'other'; $type = 'goodies'; } else { // Default is coffee! $page_title = 'Our Coffee Products'; $type = $sp_type = 'coffee'; } // Include the header file: include ('./includes/header.html'); // Require the database connection: require (MYSQL); // Call the stored procedure: $r = mysqli_query($dbc, "CALL select_categories('$sp_type')"); // For debugging purposes: //if (!$r) echo mysqli_error($dbc); // If records were returned, include the view file: if (mysqli_num_rows($r) > 0) { include ('./views/list_categories.html'); } else { // Include the error page: include ('./views/error.html'); } // Include the footer file: include ('./includes/footer.html'); ?> ------------------------------------------------------------------------------------------------------------- I followed the book exactly and don't know why I am having this trouble.. It would be really appreciated if you can tell me what the problem is.. Thanks
  9. Thank you very much, Larry. It was very useful info. I have another problem I got into now. I am going to create a new post for the problem. Please find the latest post. Thanks again for your great help.
  10. Thanks Larry, Can you tell me the title of the forum? I have been poking around the forums but don't know which one is what you are talking about. Thanks again for your help. I appreciate it.
  11. Thanks for reply, Hartley. I haven't tried that one ($r = mysqli_query($dbc, "CALL select_categories('coffee')") yet on php web page. But, the book said you can just call "CALL select_categories('coffee');" in mysql interface(phpmyadmin)... I guess I should try one you recommend on php web page instead of trying to invoke in phpmyadmin.
  12. Hi all, Thanks in advance for your help. I have been following the chapter 8. I created the database and populated according to this book. Also I put stored procedures into my mysql interface(PHPmyadmin). You can see what I put on below. -------------------------------------------------------------------------------------------------------------------- DELIMITER $$ CREATE PROCEDURE select_categories (type VARCHAR(6)) BEGIN IF type = 'coffee' THEN SELECT * FROM general_coffees ORDER by category; ELSEIF type = 'other' THEN SELECT * FROM non_coffee_categories ORDER by category; END IF; END$$ DELIMITER ; DELIMITER $$ CREATE PROCEDURE select_products(type VARCHAR(6), cat TINYINT) BEGIN IF type = 'coffee' THEN SELECT gc.description, gc.image, CONCAT("C", sc.id) AS sku, CONCAT_WS(" - ", s.size, sc.caf_decaf, sc.ground_whole, sc.price) AS name, sc.stock FROM specific_coffees AS sc INNER JOIN sizes AS s ON s.id=sc.size_id INNER JOIN general_coffees AS gc ON gc.id=sc.general_coffee_id WHERE general_coffee_id=cat AND stock>0 ORDER by name ASC; ELSEIF type = 'other' THEN SELECT ncc.description AS g_description, ncc.image AS g_image, CONCAT("O", ncp.id) AS sku, ncp.name, ncp.description, ncp.image, ncp.price, ncp.stock FROM non_coffee_products AS ncp INNER JOIN non_coffee_categories AS ncc ON ncc.id=ncp.non_coffee_category_id WHERE non_coffee_category_id=cat ORDER by date_created DESC; END IF; END$$ DELIMITER ; DELIMITER $$ CREATE PROCEDURE select_sale_items (get_all BOOLEAN) BEGIN IF get_all = 1 THEN SELECT CONCAT("O", ncp.id) AS sku, sa.price AS sale_price, ncc.category, ncp.image, ncp.name, ncp.price, ncp.stock, ncp.description FROM sales AS sa INNER JOIN non_coffee_products AS ncp ON sa.product_id=ncp.id INNER JOIN non_coffee_categories AS ncc ON ncc.id=ncp.non_coffee_category_id WHERE sa.product_type="other" AND ((NOW() BETWEEN sa.start_date AND sa.end_date) OR (NOW() > sa.start_date AND sa.end_date IS NULL) ) UNION SELECT CONCAT("C", sc.id), sa.price, gc.category, gc.image, CONCAT_WS(" - ", s.size, sc.caf_decaf, sc.ground_whole), sc.price, sc.stock, gc.description FROM sales AS sa INNER JOIN specific_coffees AS sc ON sa.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 WHERE sa.product_type="coffee" AND ((NOW() BETWEEN sa.start_date AND sa.end_date) OR (NOW() > sa.start_date AND sa.end_date IS NULL) ); ELSE (SELECT CONCAT("O", ncp.id) AS sku, sa.price AS sale_price, ncc.category, ncp.image, ncp.name FROM sales AS sa INNER JOIN non_coffee_products AS ncp ON sa.product_id=ncp.id INNER JOIN non_coffee_categories AS ncc ON ncc.id=ncp.non_coffee_category_id WHERE sa.product_type="other" AND ((NOW() BETWEEN sa.start_date AND sa.end_date) OR (NOW() > sa.start_date AND sa.end_date IS NULL) ) ORDER BY RAND() LIMIT 2) UNION (SELECT CONCAT("C", sc.id), sa.price, gc.category, gc.image, CONCAT_WS(" - ", s.size, sc.caf_decaf, sc.ground_whole) FROM sales AS sa INNER JOIN specific_coffees AS sc ON sa.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 WHERE sa.product_type="coffee" AND ((NOW() BETWEEN sa.start_date AND sa.end_date) OR (NOW() > sa.start_date AND sa.end_date IS NULL) ) ORDER BY RAND() LIMIT 2); END IF; END$$ DELIMITER ; -------------------------------------------------------------------------------------------------------------------------- It executed OK. But when I was trying to invoke it by typing "CALL select_categories('coffee'); The error message (" can't return a result set in the given context. 'coffee') is occurred. Can you help me with this problem? Thanks again and look forward to hearing from you soon.
  13. Hi Larry, I just upgrade it to Firefox 5. How can I resize them? Can you show me how to do that? Sorry for asking again. Thanks for your help. I appreciate your help. Ryan
  14. Hi Larry, Thank you for your advice. I am using firefox. It doesn't show me anything about the width. It's kinda frustrating that I can't fix this issue.. Thanks for your help. Ryan
  15. Hi Larry, Thanks for your reply. I reduced the width to 600. But it still has the same problem as before. I wonder the js file I attached has some problem. I put "tiny_mce" folder in my web root of the server. In tiny_mce, there are 'langs'folder, 'plugins' folder, 'themes' folder, 'utils' folder, licence, tiny_mce.js, tiny_mce_popup.js,and tiny_mce_src.js. So it will look like it below. www - tiny_mce - 'langs', 'plugins', 'themes', 'utils', licence, tiny_mce.js, tiny_mce_popup.js, tiny_mce_src.js. Thanks again and look forward to hearing from you soon. Ryan
  16. You can login as an administer. I will change this info right after having your advice. Admin email: forkhyun@gmail.com Amdin password : Liverfolk81 add_page.php codes I put on are below: ---------------------------------------------------------------------------------- <?php // This page is used by an administrator to create a specific page of HTML content. // This script is created in Chapter 5. // Require the configuration before any PHP code as the configuration controls error reporting: require ('./includes/config.inc.php'); // If the user isn't logged in as an administrator, redirect them: redirect_invalid_user('user_admin'); // Include the header file: $page_title = 'Add a Site Content Page'; include ('./includes/header.html'); // Require the database connection: require(MYSQL); // For storing errors: $add_page_errors = array(); // Check for a form submission: if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Check for a title: if (!empty($_POST['title'])) { $t = mysqli_real_escape_string($dbc, strip_tags($_POST['title'])); } else { $add_page_errors['title'] = 'Please enter the title!'; } // Check for a category: if (filter_var($_POST['category'], FILTER_VALIDATE_INT, array('min_range' => 1))) { $cat = $_POST['category']; } else { // No category selected. $add_page_errors['category'] = 'Please select a category!'; } // Check for a description: if (!empty($_POST['description'])) { $d = mysqli_real_escape_string($dbc, strip_tags($_POST['description'])); } else { $add_page_errors['description'] = 'Please enter the description!'; } // Check for the content: if (!empty($_POST['content'])) { $allowed = '<div><p><span><br><a><img><h1><h2><h3><h4><ul><ol><li><blockquote>'; $c = mysqli_real_escape_string($dbc, strip_tags($_POST['content'], $allowed)); } else { $add_page_errors['content'] = 'Please enter the content!'; } if (empty($add_page_errors)) { // If everything's OK. // Add the page to the database: $q = "INSERT INTO pages (category_id, title, description, content) VALUES ($cat, '$t', '$d', '$c')"; $r = mysqli_query ($dbc, $q); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. // Print a message: echo '<h4>The page has been added!</h4>'; // Clear $_POST: $_POST = array(); // Send an email to the administrator to let them know new content was added? } else { // If it did not run OK. trigger_error('The page could not be added due to a system error. We apologize for any inconvenience.'); } } // End of $add_page_errors IF. } // End of the main form submission conditional. // Need the form functions script, which defines create_form_input(): require ('includes/form_functions.inc.php'); ?> <h3>Add a Site Content Page</h3> <form action="add_page.php" method="post" accept-charset="utf-8"> <fieldset><legend>Fill out the form to add a page of content:</legend> <p><label for="title"><strong>Title</strong></label><br /><?php create_form_input('title', 'text', $add_page_errors); ?></p> <p><label for="category"><strong>Category</strong></label><br /> <select name="category"<?php if (array_key_exists('category', $add_page_errors)) echo ' class="error"'; ?>> <option>Select One</option> <?php // Retrieve all the categories and add to the pull-down menu: $q = "SELECT id, category FROM categories ORDER BY category ASC"; $r = mysqli_query ($dbc, $q); while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) { echo "<option value=\"$row[0]\""; // Check for stickyness: if (isset($_POST['category']) && ($_POST['category'] == $row[0]) ) echo ' selected="selected"'; echo ">$row[1]</option>\n"; } ?> </select><?php if (array_key_exists('category', $add_page_errors)) echo ' <span class="error">' . $add_page_errors['category'] . '</span>'; ?></p> <p><label for="description"><strong>Description</strong></label><br /><?php create_form_input('description', 'textarea', $add_page_errors); ?></p> <p><label for="content"><strong>Content</strong></label><br /><?php create_form_input('content', 'textarea', $add_page_errors); ?></p> <p><input type="submit" name="submit_button" value="Add This Page" id="submit_button" class="formbutton" /></p> </fieldset> </form> <script type="text/javascript" src="tiny_mce/tiny_mce.js"></script> <script type="text/javascript"> tinyMCE.init({ // General options mode : "exact", elements : "content", theme : "advanced", width : 800, height : 400, plugins : "advlink,advlist,autoresize,autosave,contextmenu,fullscreen,iespell,inlinepopups,media,paste,preview,safari,searchreplace,visualchars,wordcount,xhtmlxtras", // Theme options theme_advanced_buttons1 : "cut,copy,paste,pastetext,pasteword,|,undo,redo,removeformat,|,search,replace,|,cleanup,help,code,preview,visualaid,fullscreen", theme_advanced_buttons2 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,|,bullist,numlist,|,outdent,indent,blockquote,|,sub,sup,cite,abbr", theme_advanced_buttons3 : "hr,|,link,unlink,anchor,image,|,charmap,emotions,iespell,media", theme_advanced_toolbar_location : "top", theme_advanced_toolbar_align : "left", theme_advanced_statusbar_location : "bottom", theme_advanced_resizing : true, // Example content CSS (should be your site CSS) content_css : "/css/styles.css", }); </script> <!-- /TinyMCE --> <?php /* PAGE CONTENT ENDS HERE! */ // Include the footer file to complete the template: include ('./includes/footer.html'); ?> -------------------------------------------------------------------------
  17. Hi All, I made a add_page.php according to the book "effortless e-commerce". If you look at the content box on my web page (here's the link: http://ryan.divinehosting.ca/add_page.php), you will notice that your cursor starts way below the tool bar. So if I want to type something, I need to start from in the middle of this blank box. Also, if you go down hitting "enter" as you keep typing, the background of this website is showing up in this blank box.. It's weird... Thanks in advance for your help and look forward to hearing from you soon.
  18. Thanks Hartley, I appreciate your help. I adjusted it and the web page works. Thanks again for your help.
  19. If this is from my local computer. I can start with http://localhost/.. But since it's on my server. I put my server directory www. I really don't understand why it's not opening the file..
  20. Hi all, I am reading through chapter 3 and tested it on the server. I've got this error message below. ------------------------------------------------------------------------------------------------------------------- An error occurred in script '/home/ryandivi/public_html/index.php' on line 15: require(/www/includes/mysqli.inc.php) [function.require]: failed to open stream: No such file or directory Array ( [0] => Array ( [file] => /home/ryandivi/public_html/index.php [line] => 15 [function] => my_error_handler [args] => Array ( [0] => 2 [1] => require(/www/includes/mysqli.inc.php) [function.require]: failed to open stream: No such file or directory [2] => /home/ryandivi/public_html/index.php [3] => 15 [4] => Array . . . . . --------------------------------------------------------------------------------------------------------------------- As it said that it failed to open the config file, I looked at define in my config. I think there must be something wrong with connection path. I wrote my define like this below. //define the constants; define('BASE_URI','/www/'); define('BASE_URL','www.ryan.divinehosting.ca/'); define('MYSQL', BASE_URI . 'includes/mysqli.inc.php'); I am wondering if there's any problem with define('BASE_URI','/www/');. I don't know what to put for this path. My server's web root folder name is 'www'. So I put /www/ for the path.. For more information about this issue, I am putting my index.php file as well. Please see below. ------------------------------------------------------------------------------------------------------- <?php //include the config file //it should be the first (noncomment) code in your pages. include('./includes/config.inc.php'); $_SESSION['user_id'] = 1; $_SESSION['user_type'] = 'admin'; //require the header file include('./includes/header.html'); //require database connection //it connects through define in config file require(MYSQL); ?> <h3>Welcome</h3> <p>Welcome to Knowledge is Power, a site dedicated to keeping you up to date on the web security and programming information you need to know.Blah Blah Blah. Yadda, yadda, yadda.</p> <?php include('./includes/footer.html'); ?> ------------------------------------------------------------------------------- Thanks in advance and look forward to hearing from you soon.
  21. Thanks for your reply,Josee. What's the function of KEY user_id (user_id)? Is it just for easy access to user_id?
  22. Hi, I am studying the book "effortless e commerce." There are a couple of lines I don't understand. UNIQUE KEY category (category) KEY user_id (user_id) Why are they writing the same name twice? and What's the "KEY"? I only know PRIMARY KEY() and UNIQUE() from the book "PHP6 and MYSQL 5" For example, PRIMARY KEY(id) means id is a primary key to that column. And if you put UNIQUE (username) means username can not be duplicated. I don't understand these UNIQUE KEY category (category) and KEY user_id (user_id)... Thanks for your help in advance and look forward to hearing from you soon.
  23. Hi all, I coded the web pages according to the book'php6 and mysql5'. It was ok when I put it up on my local computer. However, when I put it up on my server, there's an error occurred. I don't how I can figure it out. Thank you in advance for your help. The error message I got is this: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/ryandivi/public_html/template-registration/includes/config.inc.php:69) in /home/ryandivi/public_html/template-registration/includes/header.html on line 8 I am posting my header page, config page and index page below.. ---------------------------------------------------------------------------------------------------------------------------------------------- <header page> <?php #script 16.1 - header.html //This page begins the HTML header for the site //start output buffering ob_start(); //initialize a session; session_start(); //check for a $page_title value; if(!isset($page_title)){ $page_title='User Registration'; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title><?php echo $page_title ?></title> <style type="text/css" media="screen"> @import "includes/layout.css"; </style> </head> <body> <div id="header">User Registration</div> <div id="Content"> <!-- end of header --> <config page> <?php #script 16.3 -config.inc.php /*This script: * - define constants and settings * - dictates how errors are handled * - defines useful functions */ //Document who created this site, when, why, etc //*******************************************// //************** settings *******************// //Flag variable for site status define('LIVE',FALSE); //Admin contact address; define('EMAIL','service@mascdesign.com'); //site URL(base for all redirections); define('BASE_URL','http://www.ryan.divinehosting.ca//template-registration'); //location of the mysql connection script define('MYSQL','../../mysqli_connect.php'); //adjust the time zone for PHP5.1 and greeter date_default_timezone_set('America/Toronto'); //************settings****************// //************************************// //************************************// //********error management************// //create the error handler function my_error_handler ($e_number,$e_message,$e_file,$e_line,$e_vars){ //build error message $message = "<p>An error occurred in script '$e_file' on line $e_line:$e_message\n<br/>"; //add date and time $message .= "Date/Time: ".date('n-j-Y H:i:s')."\n<br/>"; //Append $e_vars to the $message $message .= "<pre>".print_r($e_vars,1)."</pre>\n</p>"; if(!LIVE) {//Development (print the error) echo'<div class="error">'.$message.'</div><br/>'; }else{//don't show the error; //send an email to the admin; mail(EMAIL,'Site Error!',$message,'From:email@example.com'); //only print an error message if the error isn't a notice if($e_number != E_NOTICE){ echo'<div id="Error">A system error occurred. We apologize for the inconvenience.</div><br/>'; } }// end of !LIVE if }//end of my_error_handler //*********************error management**************************// //***************************************************************// ?> <index page> <?php #script 16.5 - index.php // this is the main page for the site //include the configuration file; require_once('includes/config.inc.php'); //set the page title and include the HTML header $page_title = 'Welcome to this Site!'; include('includes/header.html'); //welcome the user (by name if they are logged in); echo'<h1>Welcome'; if(isset($_SESSION['first_name'])) { echo",{$_SESSION['first_name']}!"; } echo'</h1>'; ?> <p>Thank you for visiting our website. It's our previlige to share lots of information with you, today! Blar Blar Blar... Blar. Blar...</p> <p>Blar Blar Blar Blar Blar Bla rBlar Blar Blar Blar Blar Blar Blar Blar Blar Blar Blar Blar Blar Blar Blar Blar Blar Blar Blar Blar Blar</p> <?php //include the HTML footer file; include('includes/footer.html'); ?> -------------------------------------------------------------------------------------------------------------------------------------- Thanks again and look forward to hearing from you soon.
×
×
  • Create New...