Jump to content
Larry Ullman's Book Forums

Paul

Members
  • Posts

    147
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Paul

  1. Hi all, I have created a file in Dreamweaver that is going to be a header include, as follows: <?php // Di's Soft Furnishings // header.html // The header file ob_start(); session_start(); if (!isset($page_title)) { $page_title = 'Di\'s soft Furnishings'; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><?php echo $page_title; ?></title> </head> <body> <?php echo '<p>hello</p>'; ?> </body> </html> I saved it as header.html and run it through local host (XAMPP). It displayed the ';?> after the hello. I then save the same code as header.php and run it through local host and it was perfect. Question: Does it matter if I save a file as html or php? I also understood that php could be placed within html OK. It doesn't seem to be the case here. Thanks for any help. Paul
  2. Hi all, Please take a quick look at the following code which is a page for calculating the amount of fabric needed for curtains and blinds. <?php # fabric_enquiry.php // Di's Soft Furnishings fabric enquiry page // Starts with the header include //Header include has links to home, curtains, blinds and other sf //Page title $page_title = "Di's Soft Furnishings - fabric quantity enquiry"; include ('includes/header.html'); ?> <h1>How much fabric do you need?</h1> <?php include ('includes/fabric_enquiry_curtains_inc.php'); include ('includes/fabric_enquiry_rblinds_inc.php'); ?> <h3>Other links</h3> <a href="quote.php">Get a quote for curtains and Roman Blinds</a><br /> <a href="measure_curtains.php">How to measure for curtains</a> <br /><br /> <a href="login.php">Log in to retrieve a quote</a> <?php include ('includes/footer.html'); ?> As you can see I'm weaving php and html togethor, a bit of one then the other. A general question, but what's the guidance for whether I should use echo and 'stay' in php. For instance I could write the <h1> header as: echo '<h1>How much fabric do you need?</h1>'; Is one way better to use than the other or is it just personal taste? Thinking about it my thought would be that the less times you go in and out of php the less the server needs to work and the faster the page loads. But, of course, I could be talking complete cobblers! Cheers Paul
  3. Hi again, Ignore this post I've realised what I've done. I'm using localhost and I made changes to the linked pages and then tried to access them from the homepage without having sent them to the remote server. So, in effect, the link was linking to an outdated file. I've run the linked files through localhost and now the links work correctly. Paul
  4. Hi all, I have used the following header include on every webpage, including the homepage: <?php # header.html // This is the include for the header for each page. // It starts output buffering and initialises a session. // It assigns a page title. ob_start(); session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title> <?php echo $page_title; ?> </title> </head> <body> <h1>The banner will go here</h1> <h3>Main menu</h3> <a href="../curtains.php">Curtains</a><br /> <a href="../rblinds.php">Roman Blinds</a><br /> <a href="../other_soft_furnishings.php">Other Soft Furnishings</a> I'm trying to add a page title to each page of a website by using the following code on each page. This one is for the curtains page: //Page title $page_title = "Di's Soft Furnishings - Curtains"; include ('includes/header.html'); Right. Here's the problem. When I load the homepage and say the curtains pages seperately the page title bit works and the relevant title appears at the top of the browser tab. However if I load the hompage first and then use the 'curtains' link then the title does not appear at the top of the curtains page. Is it something to do with the fact that I have included the links within the header include? I can't see why that would make a difference but something is? Cheers Paul
  5. Paul, hi. It's not in junk mail or spam. When I send emails from test1@localhost.com to test2@localhost.com they appear in the inbox. Thanks for the suggestion though. Paul
  6. Thanks Shoun, You sound like you've had a bigger game than me with this. What is Pear? Paul
  7. Morning Shoun and all, I'm not using Thunderbird, I've created my 2 test email addresses in Windows Mail. I used Windows Mail because it's local as opposed to Gmail etc. (I can't get Mercury Mail to send emails 'externally'). I set up these users in Windows Mail so that, like you, I could see that my mail() code worked. I can't. Is there a way to 'tell' Mercury Mail who to send the email from, i.e. from test1@localhost.com to test2@localhost.com? Where are localhost emails sent from? I must confess, as a beginner without much knowledge or experience of these things, that there seems to be a hole in the development process here. XAMPP, phpMyAdmin and MySQL are superb resources to test PHP, and I suspect other things that I haven't come accross yet. However there seems, from posts in this and other forums, no solid, reliable platform to test auto-email functions. I'm about to start Larrys advanced PHP5 book where, I understand, there is a section on using PHP to create HTML and CSS styled emails. I'm looking forwards to learning that, as with the project that I'm working on I would like to send statements to clients using data from their orders etc and make them look a bit more attractive that plain text. However, as it stands, I can't test them until they get into a live environment with a hosts mail server. Am I missing something? This can't be how others do it? Any thoughts? Paul PS Apologies if you're pick up a feeling of frustration here.
  8. Hiya all, Please take a look at the following code which is part of a user registration process. if (mysqli_affected_rows($dbc) == 1) { //If it did, then send the activation email to the user $body = "Thankyou for saving a quote with Di's Soft Furnishings. To activate your account, and view your quote, please click on this link:\n\n"; $body .= BASE_URL . 'activate.php?x=' . urlencode($e) . "&y=$a"; mail($trimmed['email'], 'Account Registration Confirmation', $body, 'From: Di@DisSoftFurnishings.co.uk'); } Please also refer to my recent post regarding Mercury mail. In that post I said that I've created 2 mail accounts in Windows mail both with localhost.com (using the alias settings in Mercury Mail). I can send an email from one test account to the other and back again and it works fine. However. I filled in the registration form on my registration page (name, email, password1 and password2). I used an email address which is one of the test accounts mentioned above. I ran it. It updated the user in the DB OK, so I know that bit worked. It came up with no errors. Yet, no email was received. Where can I go from here? I'm not even clear where to look. I don't know whether it's my code or my Mercury Mail setup. My feeling is that it can't be the Mercury Mail setup because I can send emails between the two test accounts. If I can't work it out I guess I'll have to test everything else, put it live (with an external host) and then test the email functionality. But that doesn't seem the correct way to do it. Thanks for any suggestions anyone can give. Paul
  9. Oooh, blimey, it's embedded the video. That's clever. There you go. Have a gander!
  10. Hi everyone, I'm typing this in the hope that it'll help other beginners who are working through Larry's book. Chapter 10 deals with using php to send emails. However, as Larry explains, you need a mail server to actually 'send' them and test them. I sort of bypassed that chapter because the idea of downloading a mail server and configuring it was just too daunting. But I now need to test something for a job so I've had to work at it. I've found a really good video that explains it from start to finish. Here's the link: . All you experienced folks out there probably know all this stuff but I haven't a clue. I wasn't even sure what a mail server was until I reached chapter 10! So a couple of things that I fell over on. First: the video talks about ip address 127.0.0.1. It appears that this is a universal ip address for localhost so that the mail server 'talks' to localhost.....or something like that. Second: For some reason I cannot get it to send emails to external addresses, i.e. blahblah@wotsit.co.uk or clueless@gmail.com. There is stuff out there about this but it looks too scary to me as it talks about using your isp settings and the last thing I want to do is mess up my 'normal' email. So I set up two accounts with windows mail. This way I can use php to send emails from one to the other. My beginners logic says that if the php scripts work for sending an email from test1@localhost.com to test2@localhost.com then they'll work for anything else. Please would someone let me know if my logic is wrong. Third: Once you set up the settings in Mercury mail, minimise the window. Don't close it. Even I know that a mail server can't send emails if it's off! It has to be 'running' in the XAMPP window. I hope this helps others. It's really not difficult with the video to guide you. Cheers Paul
  11. Antonio and Paul, Thankyou both very much for your solutions and suggestions. Paul, it worked in the end, your answer was spot-on. Antonio, I think I see what you are saying. I believe that one of the problems that Paul was answering below (the one where he needed to insert single quotes on various values) was caused by this sort of situation. The way I understand Paul's answer is that the quotes were needed because my form was created in such a way that MYSQL was treating the values as text. I notice that the only fields that didn't need the quotes were fields whoes values were integers. Would that be correct thinking? Would Antonios suggestion have reduced or eliminated this type of problem? Is there a danger, though, of creating so many tables that the wood cannot be seen for the trees? I suspect that there's a fine line here. I must confess I know very little about curtains and roman blinds either, it's my wifes business, but I've picked a humdinger (do you know that word?) as my first php project. Thanks again. Paul
  12. Hi all, Please take a look at the following code. //Retreive the user id from the registration $q = "SELECT user_id FROM dsf_users WHERE email='$e'"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); //Assign the user_id to an array to be picked up by the INSERT later on while ($dsf_users = mysqli_fetch_array($r, MYSQLI_ASSOC)) { //Does it pick up the user id correctly? echo 'The user id is' . $dsf_users['user_id'] .' '; } if (mysqli_num_rows($r) == 1) { //If it worked (it did) then insert the curtain quote into the DB, including the user_id //Check that there is a session containing all the quote information print_r($_SESSION); if ($_SESSION['quote_type'] == 'curtains') { $q = "INSERT INTO curtains (user_id, drop, track_pole, track_pole_width, heading_tape, lining, fullness, interlined, fabric_width, current_status, curtain_total_cost, curtain_quote_date) VALUES ({$dsf_users['user_id']}, {$_SESSION['drop']}, {$_SESSION['track_pole']}, {$_SESSION['track_pole_width']}, {$_SESSION['heading_tape']}, {$_SESSION['lining']}, {$_SESSION['fullness']}, {$_SESSION['interlined']}, {$_SESSION['fabric_width']}, 'quote', {$_SESSION['curtain_total_cost']}, NOW() )"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); } else { echo 'it worked for blinds'; } } Hopefully the comments should explain what I'm trying to do but in a nutshell: A user requests a quote with a form. The quote information is saved to a session. The user is then required to register in order to save their quote. After completing the registration form the above code picks up the user id and then togethor with the quote information in the session inserts the lot into a curtains table in a DB. It didn't work. Here's the error log [b]The user id is31[/b] Array ( [quote_type] => curtains [drop] => 10 [track_pole_width] => 20 [fabric_width] => 139 [track_pole] => track [lining] => regular_lining [heading_tape] => three_inch [fullness] => 2 [interlined] => no [curtain_total_cost] => 27.5 ) An error has occurred in script 'C:\xampp\htdocs\Di's Soft Furnishings\register.php' on line 151: [i]Query: INSERT INTO curtains (user_id, drop, track_pole, track_pole_width, heading_tape, lining, fullness, interlined, fabric_width, current_status, curtain_total_cost, curtain_quote_date) VALUES (, 10, track, 20, three_inch, regular_lining, 2, no, 139, 'quote', 27.5, NOW() )[/i] MySQL 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 'drop, track_pole, track_pole_width, heading_tape, lining, fullness, interlined, ' at line 2 Date/Time: 7-7-2011 13:13:37 Array ( [GLOBALS] => Array *RECURSION* [_POST] => Array ( [first_name] => fffffffff [last_name] => jjjjjjjjjjjj [email] => ff@ff.co.uk [password1] => test1 [password2] => test1 [submit] => Register to save your quote [submitted] => TRUE ) [_GET] => Array ( ) [_COOKIE] => Array ( [phpSESSID] => 8182bkr3mu2f81qh3i6fi88q60 ) [_FILES] => Array ( ) [page_title] => Registration page [_SESSION] => Array ( [quote_type] => curtains [drop] => 10 [track_pole_width] => 20 [fabric_width] => 139 [track_pole] => track [lining] => regular_lining [heading_tape] => three_inch [fullness] => 2 [interlined] => no [curtain_total_cost] => 27.5 ) [dbc] => mysqli Object ( [affected_rows] => -1 [client_info] => mysqlnd 5.0.7-dev - 091210 - $Revision: 304625 $ [client_version] => 50007 [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 'drop, track_pole, track_pole_width, heading_tape, lining, fullness, interlined, ' at line 2 [field_count] => 1 [host_info] => localhost via TCP/IP [info] => [insert_id] => 0 [server_info] => 5.5.8 [server_version] => 50508 [sqlstate] => 42000 [protocol_version] => 10 [thread_id] => 112 [warning_count] => 0 ) [trimmed] => Array ( [first_name] => fffffffff [last_name] => jjjjjjjjjjjj [email] => ff@ff.co.uk [password1] => test1 [password2] => test1 [submit] => Register to save your quote [submitted] => TRUE ) [p] => test1 [e] => ff@ff.co.uk [ln] => jjjjjjjjjjjj [fn] => fffffffff [q] => INSERT INTO curtains (user_id, drop, track_pole, track_pole_width, heading_tape, lining, fullness, interlined, fabric_width, current_status, curtain_total_cost, curtain_quote_date) VALUES (, 10, track, 20, three_inch, regular_lining, 2, no, 139, 'quote', 27.5, NOW() ) [r] => [a] => 383d20e38bb88e2f126fd40736e2fe6d [dsf_users] => ) As you can see the script picked up the user_id OK (it's 31) and the session contains data. It says that there's something wrong with my syntax. Now, looking at the query in the error message (in italics) it has every value except the user_id. Yet thescript has pciked up the user_id (in bold). It's going to be something obvious, but I can't see it! Any help would be greatly appreciated. Sorry it's a bit of an epic. Thanks Paul
  13. Arny, Hi. This is my first attempt at answering a question so please take what I'm about to offer with a huge ladle of salt. As far as I understood it the parent_id is the id of the original message not the latest message. The idea being that it's a way to track the 'list' of messages that make up a single post. See the first column on page 168 (Creating the database). As an aside, I notice that below you say that you cut and paste the code. From my very recent experience of working through the book i had the time to type the code from scratch. I know it sounds long winded but I found it a fantastic way to start remembering and becoming more familiar with the syntax. Hope this helps. Cheers Paul
  14. Hi, I have the need of a mail server to test a login script. I've just noticed that XAMPP comes with Mercury Mail. A quick read of the notes on the XAMPP localhost webpage and it looks straightforward. I'm suspicious because Larry doesn't mention it in his book in the email section as an option. Has anyone used it? Cheers Paul
  15. Hi all, Guess who's been a bonehead! I've worked it out. I have a parent script that has an 'include' that contains session_start(). This same script has 2 'includes' one of which is the curtain quote script that I'm having trouble with. So I make my changes to the curtain quote script and run it through XAMPP. Standing alone it works OK, calculates the quote. It even saves the information in the $_SESSION array and prints it out on screen. However it won't print a session id or take it to another file. It's because I'm not running the script through the parent script that contains the session_start() code. As soon as I do that it works. I only tell you this so that it may help others. I guess the botton line is that if you are testing a file that is in itself an include then you need to test it from the parent file. Does that make sense? Antonio, you might ask your friend if he's using includes! Cheers Paul
  16. Hi all, Does anyone have any ideas on this one? I've got a feeling I may be misunderstanding sessions? I thought that once a session had data saved to it then that data was available in any script within that website (in this case localhost), providing that session_start() had been started for the scripts that were involved. If that is correct is echo session_id() correct syntax? Is there a PHP configuration that I need to do? Thanks for any help you can give. If I can't get this to work then, I guess, I'll need to append it all to the url and pass it over that way. Cheers Paul
  17. Hi, Please take a look at the following code: $_SESSION['quote_type'] = 'curtains'; $_SESSION['drop'] = $drop; $_SESSION['track_pole_width'] = $track_pole_width; $_SESSION['fabric_width'] = $fabric_width; $_SESSION['track_pole'] = $track_pole; $_SESSION['lining'] = $lining; $_SESSION['heading_tape'] = $heading_tape; $_SESSION['fullness'] = $fullness; $_SESSION['interlined'] = $interlined; print_r($_SESSION); echo session_id(); The print_r($_SESSION); works perfectly. Nice long row of array contents. I then opened up another file within the same web site and inserted the same print_r($_SESSION); code to make sure that the session information was being carried over. Nothing appeared. So I added the echo session_id(); code to check the session id and compare it with the other file. No session id appeared when I ran the script. Is it possible for a session to be deleted straight after it was run? Thanks Paul
  18. Hi, Is it possible to show all the variables and their values in an entire script? I looked up the PHP manual and tried things like 'get_defined_vars()', 'print_r()', or 'var_dump()' but couldn't get them to work. They all seemed to want to know the name of the variable, whereas I want to know what variables exist. It's actually connected to my last question about sessions. I've created a script that calculates a quote for curtains (believe it or not!) which is surprisingly complicated. What is even more surprising is that it worked! However, I now want to assign all the quote criteria to a session (to save on a DB once the user has registered). Rather than trawl through the entire script adding one variable after the other I thought it might be quicker if I could just get a list of them all and cut and paste. Thanks. Paul
  19. Hi, If I want to add multiple items to a session do I need to add them 1 at a time, i.e.: S_SESSION['name'] = 'Fred'; $_SESSION['surname'] = 'Flintstone'; I tried to add them in one go using the following type of thing: $_SESSION[array('name' => 'Fred', 'surname' => 'Flintstone')]; It didn't like it! Is it possible and my syntax is just wrong or is it 1 at a time? Cheers Paul
  20. Hi all, I'm just in the process of buying a new computer and am frightening myself with just how much stuff I have on my old one that I need to move over! As far as transferring the MySql databases that I've created, both for Larry's tutorials and for work that I'm doing, is it as straightforward as just copying the contents of C:\xampp\mysql\data from one computer to another. Thanks Paul
  21. Thanks gents. So the statement if ($test) just tests that a variable exists? But what, for a variable, does 'exist' mean. NULL, TRUE, FALSE, number or text? What's it's default 'value'. Is it NULL? If you're wondering why I'm banging on about this I'm on script 16.6, lines 16 and 50. I understand what line 16 does, but does it have to be FALSE, could it just as well be NULL?
  22. Please would you guys clarify something for me. If a variable is set to FALSE, i.e. $test = FALSE, that doesn't mean the word false does it? It means FALSE as in the opposite to TRUE. Now if you do: if($test) {and so on... This will not pass the 'if' test as the variable is set to FALSE. What if it's set to TRUE? I'm not clear on the FALSE, TRUE bit of variables. Thanks Paul
  23. Thanks gents for the info. Larry. Apologies, 'it doesn't work' isn't the most helpful of comments. I'll be more informative in future. HartleySan. I like the idea of a JS forum. I felt almost guilty posting it here. I use Firebug for HTML and CSS and it's a cracking add-on. Didn't know you could use it for debugging. I'll check it out. I see your points about inline, however would I be correct in saying that the best place for lots of JS is in a seperate file referenced from the <head>, much the same as CSS? Paul
  24. Hi everyone, I know that this isn't a JS forum, but I have tried the following piece of basic form validation and it hasn't worked. Does anyone have any ideas or can recommend a good JS forum? Cheers Paul <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Fabric quantity enquiry</title> <script type="text/javascript"> function drop_onblur() { var drop = document.form1.drop; if (isNaN(drop.value) == true) { alert("Please enter a valid number"); drop.focus(); } } </script> </head> <body> <h1>Fabric Quantity Enquiry</h1> <h2>Curtains</h2> <form name="fabric_enquiry_curtains"> <p>Drop (cm): <input name="drop" onblur="drop_onblur()" type="text" size="10" maxlength="10" /></p> </form> </body> </html>
×
×
  • Create New...