Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'php'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 179 results

  1. Here's a general question... I suspect most of us have done it at some time - I certainly have - uploading a program by mistake to a server, that has an infinite loop in it (usually 'while(){....}') which means that the program whizzes round a million times sending hundreds of error messages to your e-mail address. QUESTION: Eventually the server will kill the program automatically, but is there any way (in php or otherwise server-side) to kill it? I suppose one could add a line in the loop such as $x+; if (x$>'1000'){die()} to save this embarrassment! "To err is human, but it takes a computer to REALLY $&** things up!!"
  2. There is something about php that I have trouble understand coming from using javascript like angular. How does routing in php work exactly? Like how does a php site know about going to a link (/browse/coffee/Dark+Roast/2) or a shop/product link. How does the htacess file works with the site. Currently, when going to a link the /shop/coffee, it responds by not found. I tried to look it up but I don't understand it per say as it different from the way I normally do it in javascript. <body id="page1"> <!-- header --> <div id="header"> <div class="container"> <div class="wrapper"> <ul class="top-links"> <li><a href="/index.php" class="first"><img alt="" src="/images/icon-home.gif" /></a></li> <li><a href="/cart.php"><img alt="" src="/images/icon-cart.gif" /></a></li> <li><a href="/contact.php"><img alt="" src="/images/icon-mail.gif" /></a></li> <li><a href="/sitemap.php"><img alt="" src="/images/icon-map.gif" /></a></li> </ul> <div class="logo"> <h1><a href="/index.php">Coffee</a><span>Wouldn't you love a cup right now?</span></h1> </div> </div> <ul class="nav"> <!-- MENU --> <li><a href="/shop/coffee/">Coffee</a></li> <li><a href="/shop/goodies/">Goodies</a></li> <li><a href="/shop/sales/">Sales</a></li> <li><a href="/wishlist.php">Wish List</a></li> <li><a href="/cart.php">Cart</a></li> <!-- END MENU --> </ul> </div> </div> <!-- content --> <div id="content"> <div class="container"> <div class="inside">
  3. I've just started this book and am really confused with an expression. Can somebody please explain the mechanism behind the expression, given below, used in Script 1.1 - sort.php return ($x < $y) // Creating an array $a = [1, 5]; // creating comparison function using the above expression function comp1($x, $y) { return ($x < $y); } // using uasort() uasort($a, 'comp1'); // output the result echo '<pre>' . print_r($a, 1) . '</pre>'; // creating the same function as above but interchanging the arguments position function comp2($y, $x) { return ($x < $y); } // using uasort() uasort($a, 'comp2'); // output the result echo '<pre>' . print_r($a, 1) . '</pre>'; This outputs Array ( [1] => 5 [0] => 1 ) Array ( [0] => 1 [1] => 5 ) Observation: reversing the position of arguments in function definition reverses the sort output. Can somebody please explain the 'mechanism' about using the expression return ($x < $y) - How and which values are returned.
  4. I am looking to recreate the following function from PDO to MySQLi but having some problems, I've been over the PHP website to read the functions. I'm trying to modularize my code in like the MVC pattern. public function bind($param, $value, $type=''){ if(is_null($type)){ switch(true){ case is_int($value): //Thinking something like, for integer etc $type = mysqli_stmt::bind_param(i); $type = PDO::PARAM_INT; break; case is_bool($value): $type = PDO::PARAM_BOOL; break; default: $type = PDO::PARAM_STR; } } $this->stmt->bindvalue($param,$value,$type); } Is it as simple as just replacing PDO version line to : $type = mysqli_stmt::bind(i); or just putting $type = i; Then in my class I am trying to call the bind function: $database ->bind($stmt,$ype,$variables); $database->execute(); Any help would be much appreciated Regards My Setup Chrome Windows XP Wamp SublimeText
  5. OS: Windows 7 php version: 5.5.8 (running on EasyPHP Dev Server 14.1 VC11) Browser: Firefox 40.0.2 (same results in Chrome and IE) I am having problems with the show_image script in chapter 11. When I select an image from the list it opens a popup window of the appropriate size but with no image. In firefox I get the error message: 'The image "http://127.0.0.1/scripts/site/show_image.php?image=Picture.png"cannot be displayed because it contains errors.' When I use the Web Developer menu to View Response Headers all is as expected except that it lists Content-Length: 0. I commented out the header calls and replaced them with echos: echo "Content-Type: {$info['mime']}</br>"; echo "Content-Disposition: inline; filename=\"$name\"</br>"; echo "Content-Length: $fs"; Which return the values you would expect: Content-Type: image/png Content-Disposition: inline; filename="Picture.png" Content-Length: 35880 I changed the Content-Disposition to attachment. The files download as normal with the appropriate file names but have a size of 0. When I try to open them I get the error message: "Windows Photo Viewer can't display this picture because the file is empty." I double checked the files in the upload folder and they are all normal .png files. My code is below. Any advice you can offer would be very gratefully received. Adam show_image.php <?php $name = FALSE; if (isset($_GET['image'])) { //echo 'Image set </br>'; $ext = strtolower(substr($_GET['image'], -4)); if (($ext == '.jpg') OR ($ext == 'jpeg') OR ($ext == '.png')) { //echo 'Correct ext </br>'; $image = "../uploads/{$_GET['image']}"; if (file_exists($image) && (is_file($image))) { //echo 'File exists </br>'; $name = $_GET['image']; } } } if (!$name) { //echo 'Unavailable'; $image = 'images/unavailable.png'; $name = 'unavailable.png'; } $info = getimagesize($image); $fs = filesize($image); header ("Content-Type: {$info['mime']}\n"); header ("Content-Disposition: inline; filename=\"$name\"\n"); header ("Content-Length: $fs"); //echo "Content-Type: {$info['mime']}</br>"; //echo "Content-Disposition: inline; filename=\"$name\"</br>"; //echo "Content-Length: $fs"; images.php <!DOCTYPE html PUBLIC "-//W3C// DTD XHTML 1.0 Transitional//EN" "http:/www.w3.org/TR/xhtml/DTD/xhtml1-transitional.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>Images</title> <script type="text/javascript" charset="utf-8" src="js/function.js"></script> </head> <body> <p>Click on an image to view it in a separate window.</p> <ul> <?php # Script 11.4 - images.php $dir = '../uploads'; $files = scandir($dir); foreach ($files as $image) { if (substr($image, 0 , 1) != '.') { $image_size = getimagesize ("$dir/$image"); $image_name = urlencode($image); echo "<li><a href=\"javascript:create_window('$image_name',$image_size[0],$image_size[1])\">$image</a></li>\n"; } } ?> </ul> </body> </html> function.js // Script 11.3 - function.js function create_window (image, width, height) { width = width + 10; height = height + 10; if (window.popup && !window.popup.closed) { window.popup.resizeTo(width, height); } var specs = "location=no, scrollbars=no, menubars=no, toolbars=no, resizeable=yes, left=0, top=0, width=" + width + ", height=" + height; var url = "show_image.php?image=" + image; popup = window.open(url, "ImageWindow", specs); popup.focus(); }
  6. Hi Larry, Hope your having a good day today as you read this message. I just want to get some advice from you personally. My problem is I really would like to be a good programmer like you larry. But I think that cannot be accomplished easily. I just wanna know what are your strategies when your just starting out as a developer. How many hours you read a book in PHP js or mysql? and how do you know if its time to move in a diff topic like ex. procedural to object oriented. Coz I think I'm having a bad habit of reading a book like, after I read a single book i'll read another book right away then I tend to forget what i've learned in the previous book. So what i usually do is I will try go back to the previous book just to refresh what i've learned. And i'm not sure if I'm doin the correct way to learn. I'm really amazed on you larry bec you know not only 1 programming language. So I just wanna know your strategies on learning. I'm very sorry for my english by the way, and I know your a super busy person. I will really appreciate your reply Larry. And I hope you understand my point. Thank you so much in advance. Regards, Jan
  7. I'm having an issue with mysql_real_escape_string. This is used to display a custom post type (food menu items) for the WooThemes Diner theme (for WordPress). Food menu items no longer display on the Diner menu page because they are being called with mysql_real_escape_string. What is the proper way to call these items? Theme: Diner by WooThemes version 1.9.8 (now retired from active support) Affected file: admin-interface.php Lines: 111 & 118 /*-----------------------------------------------------------------------------------*/ /* WooThemes Admin Interface - woothemes_add_admin */ /*-----------------------------------------------------------------------------------*/ if ( ! function_exists( 'woothemes_add_admin' ) ) { function woothemes_add_admin() { global $query_string; global $current_user; $current_user_id = $current_user->user_login; $super_user = get_option( 'framework_woo_super_user' ); $themename = get_option( 'woo_themename' ); $shortname = get_option( 'woo_shortname' ); // Reset the settings, sanitizing the various requests made. // Use a SWITCH to determine which settings to update. /* Make sure we're making a request. ------------------------------------------------------------*/ if ( isset( $_REQUEST['page'] ) ) { // Sanitize page being requested. $_page = ''; $_page = mysql_real_escape_string( strtolower( trim( strip_tags( $_REQUEST['page'] ) ) ) ); // Sanitize action being requested. $_action = ''; if ( isset( $_REQUEST['woo_save'] ) ) { $_action = mysql_real_escape_string( strtolower( trim( strip_tags( $_REQUEST['woo_save'] ) ) ) ); } // End IF Statement // If the action is "reset", run the SWITCH. /* Perform settings reset. ------------------------------------------------------------*/
  8. So...I'm just getting really frustrated now. I've been reading through several of these chapters several times. My school always tends to not choose books well. On to the issue though. In several sections I've noted it stating "Connect to MySQL and select the forum database." This is where the issue lies. I have MySQL and PHP installed in both operating systems of my laptop (Linux and Windows) and in neither does the referenced database exist. The book does not even state WHERE or HOW to have this included. How is a person supposed to follow the examples if some crucial components were left out? It's like giving directions by saying "Just follow me" while in a car to a person on a bicycle. Saying follow me would be completely worthless. If someone can at least point me in the right direction to actually have these referenced databases...or to a quality book. Either way.
  9. Ok I haven't followed the code 100% by which I mean only that I didn't include the XHTML parts in the <!DOCTYPE> tag. I understand that this is not vital however. Other than that I think I have followed it correctly. I keep getting http error 500 in the browser however when I try to load it. However other php scripts seem to load fine so I don't think it's a problem with MAMP. Here is my code: <!DOCTYPE html> <html> <head> <meta charset="utf-8" http-equiv="Content-Type" content="text/html"> <title>Calendar</title> </head> <body> <form action="calendar.php" method="post"> <?php # Script 2.6 - Calendar.php //This script makes 3 pulldown menus //For an html form: months, days, years. //make months array $months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); //make the days and years array $days = range (1, 31); $years = range (2011, 2021); //make the months pull down menu: echo '<select name="month">'; for each ($months as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; //make the days pull-down menu: echo '<select name="day">'; foreach ($days as $value) { echo "<option value=\"$value\">$value</option>\n"; } echo '</select>'; //make the years pull-down menu: echo '<select name="year">'; foreach ($year as $value) { echo "<option value=\"$value\"> $value</option>\n"; } echo "</select>"; ?> </form> </body> </html> It's probably something incredibly obvious and embarrassing but any help would be gratefully received. I'm going to skip ahead and read the section of bug fixing while I wait for a response so maybe I will find the answer there. Thanks in advance.
  10. In chapter 4 if I click on the Account tab once logged in, no links appear that allow me to change my password or logout, the account link is a dead link?. It is supposed to give me the option to logout and other links too. I am using the files from the download on this site. I finally found the problem, there is no bootstrap.min.js file in the downloads for this book. That is why the dropdown menu wasn't working. I went to the bootstrap site and downloaded and now it works fine. This really should be in the download files...
  11. In the source code and as well as the book you write if (isset($_SESSION['user_id']) && !isset($_SESSION['user_not_expired'])) { echo '<div class="alert"><h4>Expired Account</h4>Thank you for your interest in this content. Unfortunately your account has expired. Please <a href="renew.php">renew your account</a> in order to access site content.</div>'; } elseif (!isset($_SESSION['user_id'])) { echo '<div class="alert">Thank you for your interest in this content. You must be logged in as a registered user to view site content.</div>'; } and it displays the error that the member needs to renew, However I set the date to expire a month out on both my admin and member logins. when I take out the "!" from the second parameter it fixes the problem and the error message goes away. Was the "!" a mistake or am I not doing something correctly? I have been running off of the full scripts download and only tweaking things to sync up with my database. Also after I removed the "!" when I click on a category after it displays no error and I go to a page.php and click back to a category, or click on a different/same category I get the error to renew. Insights would be greatly appreciated.
  12. On page 124 it says you can use sql commands from your website to populate the database. But the sql commands I got from the download don't have any sample content, all that is in the sql commands is the commands to add the tables to the database. No content. Where can I get the file with the data to populate the tables. Please indicate the url where I can download that. I am trying to populate the pages myself but I keep getting the error which says Please select a category! I added 2 numeric categories to the categories table, but the form still won't accept it. There seems to be a problem with the code of the select menu. I could really use some help with this part of the book. Some help would be appreciated.
  13. hello, I have starting reading the PHP and MySQL 4th edition book by LarryUllman. So far I have completed first four chapters and now starting 5th chapter. But, with time as I read further, I also want to develop good skills i.e be good in what I am learning. So can anyone suggest me some startup projects? or scripts etc I can try to code, so I can be more good in programming. Regards,
  14. Hi Larry. I have a problem with this script. The table show me files list correctly with name and size. When I click on link popup appear perfectly resized but no image was loaded. Popup show a copy of show_image.php resized. No errors on firebug. If I change: var url = "show_image.php?image="+image; with var url = "upload/"+image; everythings works fine. any suggestions? Sorry for my english. Greetings Cecchi Luca
  15. I am working on the Admin area for the coffee shop site, and I am encountering an error when the query to get all products to list them on the page. I cut and paste the query because it was so complicated, thinking I would make a syntax error. I am getting an error anyway! An error occurred in script 'C:\vhosts\clever-coffee.net\html\admin\add_inventory.php' on line 94: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given Array( [0] => Array ( [function] => my_error_handler [args] => Array ( [0] => 2 [1] => mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given [2] => C:\vhosts\clever-coffee.net\html\admin\add_inventory.php [3] => 94 [4] => Array ( [_GET] => Array ( ) [_POST] => Array ( ) [_COOKIE] => Array ( [SESSION] => 115cadb3f0e62db701dc0055e125b213 [PHPSESSID] => 115cadb3f0e62db701dc0055e125b213 ) [_FILES] => Array ( ) [_SERVER] => Array ( [HTTP_HOST] => clever-coffee.net [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.1; rv:40.0) Gecko/20100101 Firefox/40.0 FirePHP/0.7.4 [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 [HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.5 [HTTP_ACCEPT_ENCODING] => gzip, deflate [HTTP_REFERER] => http://clever-coffee.net/html/admin/add_coffee.php [HTTP_COOKIE] => SESSION=115cadb3f0e62db701dc0055e125b213; PHPSESSID=115cadb3f0e62db701dc0055e125b213 [HTTP_X_INSIGHT] => activate [HTTP_CONNECTION] => keep-alive [HTTP_CACHE_CONTROL] => max-age=0 [PATH] => C:\Program Files\ActiveState Komodo Edit 9 nightly\;C:\ProgramData\Oracle\Java\javapath;C:\ImageMagick;C:\Python27\;C:\Python27\Scripts;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\PROGRA~1\IBM\CLIENT~1;C:\PROGRA~1\IBM\CLIENT~1\Shared;C:\PROGRA~1\IBM\CLIENT~1\Emulator;c:\Program Files\Java\jdk1.7.0_45\bin;C:\Program Files\Java\jdk1.7.0_51\/bin;C:\Apache Subversion 1.8.8\bin;C:\limejs\bin;C:\DevStack\MariaDB10\bin;c:\DevStack\php;c:\DevStack\php\ext;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\GnuWin32\bin;c:\drush;C:\PostgreSQL;C:\PostgreSQL\bin;C:\MinGW\bin;C:\devtools\bin\Ruby200\bin;C:\Windows\system32\WindowsPowerShell\v1.0\;C:\Python27\;C:\Python27\Scripts;C:\ImageMagick;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\PROGRA~1\IBM\CLIENT~1;C:\PROGRA~1\IBM\CLIENT~1\Shared;C:\PROGRA~1\IBM\CLIENT~1\Emulator;c:\Program Files\Java\jdk1.7.0_45\bin;C:\Program Files\Java\jdk1.7.0_51\/bin;C:\Apache Subversion 1.8.8\bin;C:\limejs\bin;C:\DevStack\mysql-5.6.19\bin;C:\DevStack\mysql-5.6.19\;C:\DevStack\mysql-5.6.19\Doctrine extensions for PHP\;c:\DevStack\php;c:\DevStack\php\ext;C:\Program Files\nodejs\;C:\Users\vmielke\AppData\Roaming\npm;C:\ProgramData\chocolatey\bin;C:\devtools\bin;\Git\bin;\Git\cmd;C:\devtools\bin\ruby\bin;C:\Users\vmielke\.gems;C:\Users\vmielke\.gems\bin [SystemRoot] => C:\Windows [COMSPEC] => C:\Windows\system32\cmd.exe [PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.RB;.RBW [WINDIR] => C:\Windows [SERVER_SIGNATURE] => [SERVER_SOFTWARE] => Apache/2.4.16 (Win32) OpenSSL/1.0.2d PHP/5.5.14 [SERVER_NAME] => clever-coffee.net [SERVER_ADDR] => 127.0.0.1 [SERVER_PORT] => 80 [REMOTE_ADDR] => 127.0.0.1 [DOCUMENT_ROOT] => C:/vhosts/clever-coffee.net [REQUEST_SCHEME] => http [CONTEXT_PREFIX] => [CONTEXT_DOCUMENT_ROOT] => C:/vhosts/clever-coffee.net [SERVER_ADMIN] => admin@clever-coffee.net [SCRIPT_FILENAME] => C:/vhosts/clever-coffee.net/html/admin/add_inventory.php [REMOTE_PORT] => 58816 [REMOTE_USER] => vmielke [AUTH_TYPE] => Basic [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_PROTOCOL] => HTTP/1.1 [REQUEST_METHOD] => GET [QUERY_STRING] => [REQUEST_URI] => /html/admin/add_inventory.php [SCRIPT_NAME] => /html/admin/add_inventory.php [PHP_SELF] => /html/admin/add_inventory.php [PHP_AUTH_USER] => vmielke [PHP_AUTH_PW] => password [REQUEST_TIME_FLOAT] => 1441830236.003 [REQUEST_TIME] => 1441830236 ) [connect] => mysqli Object ( [affected_rows] => -1 [client_info] => mysqlnd 5.0.11-dev - 20120503 - $Id: bf9ad53b11c9a57efdb1057292d73b928b8c5c77 $ [client_version] => 50011 [connect_errno] => 0 [connect_error] => [errno] => 1054 [error] => Unknown column 'sc.size' in 'order clause' [error_list] => Array ( [0] => Array ( [errno] => 1054 [sqlstate] => 42S22 [error] => Unknown column 'sc.size' in 'order clause' ) ) [field_count] => 0 [host_info] => 127.0.0.1 via TCP/IP [info] => [insert_id] => 0 [server_info] => 5.5.5-10.0.17-MariaDB [server_version] => 50505 [stat] => Uptime: 116256 Threads: 1 Questions: 1928 Slow queries: 0 Opens: 25 Flush tables: 1 Open tables: 88 Queries per second avg: 0.016 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 375 [warning_count] => 0 ) [page_title] => Add Inventory [message] => [affected] => 0 [_SESSION] => Array ( ) [query3] => (SELECT CONCAT("G", ncp.id) AS sku, ncc.category, ncp.name, FORMAT(ncp.price/100, 2) AS price, ncp.stock FROM non_coffee_products AS ncp INNER JOIN non_coffee_categories AS ncc ON ncc.id=ncp.non_coffee_category_id ORDER BY category, name) UNION (SELECT CONCAT("C", sc.id),gc.category, CONCAT_WS(" - ", s.size, sc.caf_decaf, sc.ground_whole), FORMAT(sc.price/100, 2), sc.stockFROM specific_coffees AS sc INNER JOIN sizes AS s ON s.id=sc.size_id INNER JOIN general_coffees AS gcON gc.id=sc.general_coffee_id ORDER BY sc.general_coffee_id, sc.size, sc.caf_decaf, sc.ground_whole) [result] => ) ) ) [1] => Array ( [file] => C:\vhosts\clever-coffee.net\html\admin\add_inventory.php [line] => 94 [function] => mysqli_fetch_array [args] => Array ( [0] => [1] => 1 ) ))
  16. I have a website that I am going to turn into a store and I am reading your book. It says that it might be best to use an ssl connection only on pages where it is needed. I don't know how to implement ssl only on specific pages. How do we do that. Right now I only know how to either add it to every page using the .htaccess file or not at all. What code do I use to only make some pages secure? Because if I only use https on some links, if I click on a page of my site that doesn't have https and then click on a page that does, my browser then makes all the other links I click on in my site use https too. Is that normal. That is also after I remove my .htaccess code that makes all pages contain https.
  17. If I wanted to automatically send an email to one of my subscribers to let them know that their subscription had expired or was about to expire, would that be part of the IPN code?
  18. This is an adaptation of the view_cart.php script in ch 19. It had worked previously until I changed servers/web hosting. It may be coincidental, however, when changing cart quantity to zero, it will either throw an error (undefined total variable) or add additional products to cart which were previously deleted in the same session. All other functions work propertly, including "add to cart" and "checkout" when quantities are not changed to zero. Any suggestions would be greatly appreciated. <div class="generalarticle"> <?php // add_cart.php $cart = $_SESSION['cart']; // Check if the form has been submitted (to update the cart): if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Change any quantities: foreach ($_POST['qty'] as $k => $v) { // Must be integers! $pid = (int) $k; $qty = (int) $v; if ( $qty == 0 ) { // Delete. unset ($_SESSION['cart'][$pid]); } elseif ( $qty > 0 ) { // Change quantity. $_SESSION['cart'][$pid]['quantity'] = $qty; } } // End of FOREACH. } // End of SUBMITTED IF. // Display the cart if it's not empty... if (!empty($_SESSION['cart'])) { // Retrieve all of the information for the prints in the cart: require ('../mysqli_connect.php'); // Connect to the database. $q = "SELECT * FROM products WHERE productID IN ("; foreach ($_SESSION['cart'] as $pid => $value) { $q .= $pid . ','; } $q = substr($q, 0, -1) . ') ORDER BY productName ASC'; $r = mysqli_query ($dbc, $q); // Create a form and a table: echo '<form action="https://www.mysite.net/view-cart/" method="post"> <fieldset class="checkout"> <legend class="checkout">My Shopping Cart</legend> <table border="0" width="90%" cellspacing="3" cellpadding="3" align="center"> <tr class="checkout" > <td class="checkout" align="left" width="30%"><b>Item Name</b></td> <td class="checkout" align="right" width="10%"><b>Price</b></td> <td class="checkout" align="right" width="10%"><b>Shipping</b></td> <td class="checkout" align="center" width="10%"><b>Qty</b></td> <td class="checkout" align="right" width="10%"><b>Total Price</b></td> </tr> '; // Print each item... $total = 0; // Total cost of the order. while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC)) { // Calculate the total and sub-totals. $subtotal = (($_SESSION['cart'][$row['productID']]['quantity'] * $_SESSION['cart'][$row['productID']]['price']) + ($_SESSION['cart'][$row['productID']]['quantity'] * $_SESSION['cart'][$row['productID']]['shipping'])); $total += $subtotal; // Print the row: echo "\t<tr class=\"checkout\"> <td class=\"checkout\" align=\"left\">{$row['productName']}</td> <td class=\"checkout\" align=\"right\">\${$_SESSION['cart'][$row['productID']]['price']}</td> <td class=\"checkout\" align=\"right\">\${$_SESSION['cart'][$row['productID']]['shipping']}</td> <td class=\"checkout\" align=\"center\"><input type=\"text\" size=\"3\" name=\"qty[{$row['productID']}]\" value=\"{$_SESSION['cart'][$row['productID']]['quantity']}\" /></td> <td class=\"checkout\" align=\"right\">$" . number_format ($subtotal, 2) . "</td> </tr>\n"; } // End of the WHILE loop. mysqli_close($dbc); // Close the database connection. // Print the total, close the table, and the form: echo '<tr> <td class="checkout" colspan="4" align="right"><b>Total:</b></td> <td class="checkout" align="right">$' . number_format ($total, 2) . '</td> </tr> </table> <div align="center"><input type="submit" name="submit" value="Update My Cart" /></div> </form> <p align="center">Enter a quantity of 0 to remove an item. <br /><br /><a href="https://www.mysite.net/checkout/">Checkout</a> or <a href="https://www.mysite.net/real-estate-advertisement-packages/">Continue Shopping</a>.</p></fieldset>'; } else { echo '<p>Your cart is currently empty.</p>'; } $_SESSION['total'] = $total; // carry total to checkout $_SESSION['cart'] = $cart; // carry total to checkout ?> </div> <div class="sidebar"></div> <div class="spacer"></div> </div></div>
  19. I am wondering if there is a way to use this book without performing the complex joins that have UNION statements in them. I think it is chapter 9 or 10 of the book, the chapter that shows the most complex mysql statements. How could I go about using this book without using those complex mysql joins.
  20. In the following code, (I know the if statement isn't complete, I am referring to the part before it) I am unclear why (int) is used, after using php for over a year I have never really understood when I should use (int). Is it to make sure the returned number is changed from a decimal to an integer?? Please explain why it is used in this block of code. It is from chapter 6 in the ipn.php script. if (mysqli_num_rows($r) === 0){ $uid = (isset($_POST['custom'])) ? (int) $_POST['custom'] : 0; $status = escape_data($_POST['payment_status'], $dbc); $amount = (int) ($_POST['mc_gross'] * 100); $q = "INSERT INTO orders (user_id, transaction_id, payment_status, payment_amount) VALUES ($uid, '$txn_id', '$status', $amount)"; $r = mysqli_query($dbc, $q); if (mysqli_affected_rows($dbc) === 1){ } }
  21. I must be missing something very basic but I'm stuck after several hrs of trying various solutions to this apparent function re-declaration in my config.inc.php file. Possibly after staring at the code for so long I just can't see it any more. But, I keep getting an error: Cannot redeclare my_error_handler() (previously declared in C:\xampp\htdocs\muztash\config\config.inc.php:64) in C:\xampp\htdocs\muztash\config\config.inc.php on line 91 The error seems to say that the function is being declared twice on the same page. Line 64 is the 1st line of the actual declaration: function my_error_handler($e_number,$e_message,$e_file,$e_line,$e_vars) { Line 91 is the ending } of the declaration. It matches the opening { on line 64 and there are no brace mismatches inside the declaration - which pretty closely follows the example code in the book. I have a couple of other questions but I'll focus on this one first. Thanks to whoever can help me with this.
  22. On page 117 Larry forgot to enter this line of code at the beginning of the script. if ($_SERVER['REQUEST_METHOD'] === 'POST') { Larry should post a full forum post with all the errors in this book to help us out, it is very frustrating having to try and make scripts work with errors in them, especially when we are not as experienced as Larry. I will post every error I find in this book in this forum as well as the solutions. So far I have found 3 errors in the book and I am only at chapter 5.
  23. What is the difference between mysqli_real_escape_string and escape_data(). When should we use escape_data() as opposed to mysqli_real_escape_string.
  24. In the ecommerce book, in chapter 3, you include files like so: include('./includes/header.html'); doesn't include('includes/header.html') do the same thing? Why use the ./ I don't understand. This wasn't covered in the other book I read from you php and mysql 4th edition.
  25. I'm used to using $_POST to handle my form data. In chapter 2, Mr Ullman states to use $_REQUEST. I did look up $_REQUEST on php.net and it says that it contains data for $_GET, $_POST, and $_COOKIE. Does that mean I no longer need to bother with $_GET or $_POST and just use $_REQUEST going forward? Sorry for the amateur question. I've done some PHP programming in the past and I'm trying to get back into it (hopefully in the correct way). Thank, James
×
×
  • Create New...