Jump to content
Larry Ullman's Book Forums

Emilie

Members
  • Posts

    22
  • Joined

  • Last visited

  • Days Won

    9

Emilie last won the day on September 25 2014

Emilie had the most liked content!

Emilie's Achievements

Newbie

Newbie (1/14)

19

Reputation

  1. Hello, On this line, why are you using quotes and concatenation? if (isset($_POST['SiteTypeID']) && ($_POST['SiteTypeID'] == '. $key . ')) echo 'selected="selected">'; I hope this helps, Emilie
  2. Hello, Nick, This is exactly what you should NOT do in order to run a PHP file. Firefox is just a browser. It knows how to open and display the contents of HTML files, but on its own it doesn’t know what to do with a PHP file. For Firefox, a PHP file is just a text file, or a HTML file if your PHP is inside a HTML file, which is why it displays everything in this file, including your PHP code. For your PHP code to be run as such, the PHP file must be sent to your local server (XAMPP), where the PHP interpreter will parse the code and send it back to Firefox (as HTML), for Firefox to display it. Which is why Larry told you : This means you cannot just use File/Open in Firefox. If you do that, the address will begin with : file:/// This is the path on your computer. It tells Firefox where the file is, it doesn’t tell it that this file should be sent to XAMPP and the PHP interpreter for processing. For this to happen, the address in the browser must begin with http://. If you kept your htdocs folder inside the xampp folder (the default place for it), the address in the browser will probably begin with: http://localhost/xampp/. For instance, the "Welcome" file to XAMPP runs at this address : http://localhost/xampp/index.php. The index.php file is just inside your htdocs folder. Try to open this file using File/Open in Firefox (the path is probably: file:///C:/xampp/htdocs/index.php, if your xampp folder is right at the first level inside C:)… and see what happens ! Don’t worry. Your XAMPP installation is probably just fine. The problem is only that you opened the PHP file instead of running it through the PHP interpreter. Try and read the beginning of chapter 1 again. Larry explains it very clearly… although I know it took me a long time before really understanding how things work between the local server, the PHP interpreter and the browser. I hope this helps, Emilie
  3. I’m sure it is beneficial! And I hope I’ll see the light some day. ;-)
  4. Thanks for the tip. I’ll try this in my own projects! In theory, I agree. But I don’t know why, absolute paths usually don’t work for me for URIs. Absolute URLs work fine, absolute URIs don’t, and I really can’t understand why.
  5. Hello, hwadler, Paths are one of the real pains of web programming! Your best bet is to create constants for the different paths you will need for your projects. Let’s say my files are organised like this: root_folder index.php includes // I actually use another, less obvious name config.inc.php header.php navigation.php footer.php css styles.css images js pages_folder some_page.php sub_folder some_other_page.php I define the following paths : if ($_SERVER['HTTP_HOST'] == 'localhost:8888') { define('LIVE', FALSE); define('BDD', '/Users/my_account/htdocs/bdd_connect.php'); define('BASE', 'http://localhost:8888/root_folder/'); define('BASE_PAGES', BASE . 'pages_folder/'); define('BASE_SUB', BASE_PAGES . 'sub_folder/'); } else { define('LIVE', TRUE); define('BDD', '/home/my_account/bdd_connect.php'); define('BASE', 'http://www.domain.com/root_folder/'); // this folder // is probably called www or public_html define('BASE_PAGES', BASE . 'pages_folder/'); define('BASE_SUB', BASE_PAGES . 'sub_folder/'); } Then I create constants for the different paths that vary according to the folder I’m in when calling them: if (dirname($_SERVER['PHP_SELF']) == '/root_folder') { define('BASE_CSS', 'css/'); define('BASE_JS', 'js/'); define('BASE_IMAGES', 'images/'); define('BASE_INCLUDES', 'includes/'); } elseif (dirname($_SERVER['PHP_SELF']) == '/root_folder/pages_folder') { define('INDEX', '../index.php'); define('BASE_CSS', '../css/'); define('BASE_JS', '../js/'); define('BASE_IMAGES', '../images/'); define('BASE_INCLUDES', '../includes/'); } elseif (dirname($_SERVER['PHP_SELF']) == '/root_folder/pages_folder/sub_folder') { define('INDEX', '../../index.php'); define('BASE_CSS', '../../css/'); define('BASE_JS', '../../js/'); define('BASE_IMAGES', '../../images/'); define('BASE_INCLUDES', '../../includes/'); } else { define('BASE_CSS', NULL); define('BASE_JS', NULL); define('BASE_IMAGES', NULL); define('BASE_INCLUDES', NULL); } In the header.php file, I call the CSS files like this : <link rel="stylesheet" href="<?php print BASE_CSS . 'styles.css'; ?>"> This will work whether the header.php file is in index.php or in some_page.php or in some_other_page.php. In the different files inside the pages_folder, I call the configuration file like this: require_once('../includes/config.inc.php'); I call the header, navigation and footer files like this : include(BASE_INCLUDES.'header.php'); include(BASE_INCLUDES.'navigation.php'); include(BASE_INCLUDES.'footer.php’); In the different files inside the sub_folder, the call for the configuration file is different since the constants are not defined until the configuration file has been included: require_once('../../includes/config.inc.php'); On the other hand, the header, navigation and footer files are called everywhere the same way since the constants can be used: include(BASE_INCLUDES.'header.php'); I’m sure programmers better than I am manage things more efficiently, but this has solved all my problems with paths ! I hope this helps, Emilie
  6. Hello, I understand. In order to avoid this kind of problem, just use the 'code' tags: the icon is in the middle on the bottom line and looks like this: < > It will also apply syntax coloring, which helps read the code. I hope this helps, Emilie
  7. Hello, You repeatedly used semi-colons instead of ampersands in the URLs : echo '<a href="view_users95.php?s=' . ($start - $display) . ';p=' . $pages . ';sort=' . $sort .'">Previous</a> '; Check all your URLs! I hope this helps, Emilie
  8. Hello, Another typo: ContractWitnessed='0, The closing quotation mark is missing. Also, if your ID is numeric, you should not quote it: where (ID='23') If this doesn't do the trick, I would suggest testing a few lines only at a time, until you find where the query goes wrong. I hope this helps, Emilie
  9. Hello, There's a typo in the line you highlighted in red: you forgot the concatenation dots around $image[3]: echo "<div align=\"center\"><img src=\"images?image=$pid&name=" . urlencode($row['image_name']) . "\" . $image[3] . alt=\"{$row['print_name']}\" /></div>\n"; I hope this helps, Emilie
  10. Hello, MySQL doesn't 'know' the variables you created with PHP. In order to test your query, you need to replace the variables with their values. I hope this helps, Emilie
  11. I see what you mean. I hadn't thought of that, because I'm not concerned with the book being viewed from the web, at least for the time being. I only needed some means of opening those huge HTML files and editing them. I'm just an amateur programmer, so I first tried to open this 70 MB file with my usual text editor (BBEdit), and although I've been able to edit a 350 MB file with BBEdit (although very, very slowly), I couldn't open this 70 MB file with BBEdit. I was going through Larry Ullman's "Advanced PHP" book at the time, and through chapter 12 more specifically, so I just thought I would have a go with PHP CLI. It worked (with help from Antonio Conte!), and it is so much quicker than using a text editor that I now use it to edit huge files. But I'll keep in mind your idea of storing the text in a DB and generating the HTML on the fly if I ever need these books to be viewed from the web.
  12. Not all that insane since it represents a whole book and 7 MB was before minimizing the file. Look at the digital versions of computer books, and you'll see they are 10 to 50 MB. The HTML file is the largest file within an ebook format (ePub, mobi, etc.).
  13. Hello, HartleySan, This 70 Mb HTML file was probably created with Word or some other unsuitable application. Hence loads of unnecessary style attributes inside HTML elements, empty div elements, duplicate links (some appeared up to 20 times on one line). After "cleaning", it became approximately a 7 Mb file! Emilie
  14. Hello, I think you can leave them as they are for now. If there are exercises where you need the registration date, you can change the registration date for some of them then, or add users so as to have a diversity of registration dates. Emilie
  15. Hello, What is "wrong", according to you? The registration date is the same for all users because you entered all of them at one go into the database, and therefore the timestamp corresponding to NOW() is the same for everyone. Because of that, ordering the results by registration_date DESC has no real meaning. I hope this helps, Emilie
×
×
  • Create New...