Jump to content
Larry Ullman's Book Forums

Paul

Members
  • Posts

    147
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by Paul

  1. Hi HartleySan,

    Thanks for the answer.

    1. The $curtain_price_total was initialised, it was at the top of the page and I didn't include it.

    $curtain_price_total = 0;
    

    2. I changed the code to

    $curtain_price_total += (int)$cur_v;

    It didn't work unfortunately. I did think about adding the '(int)' within the foreach but some of the values are strings.

     

    Thanks anyway.

    Paul

  2. Hi rob,

    Thanks for the answer. I tried removing the 'float' part of the number_format code and it made no difference. I take your point though, I can see why it wouldn't be needed. I'll bear that in mind and change it where I've used it in other areas.

     

    However, if it were a formatting issue then would that make the 'curtain_price_total' variable incorrect?

     

    Cheers

    Paul

  3. Hi all,
    I'm querying a DB for basket contents. I'm then using a foreach to display and then add the totals togethor. The grand total is then being displayed below the list of items in the basket. All pretty standard stuff. However if the amount of one of the items in the basket is greater that 999 it just counts the number of thousands, i.e.  £1,245.60 will be counted as 1. £2,842.70 is counted as 2. £22,168.50 is counted as 22.
     
    Relevant code

    foreach ($_SESSION['curtain_basket'] as $curtain_title => $curtain_value)
    	{	
    		echo'<tr>';
    		foreach ($curtain_value as $cur_t => $cur_v)
    		{
    			echo'
    			<td><p>'. $cur_v . '</p></td>
    			';			
    			
    		}
    		echo'
    		<td><input name="curtain_remove" type="checkbox" value="' . $curtain_title . '" /></td>
    		<td><p class="tiny_text">Remove?</p></td>
    		</tr>';
    		echo'</br>';
    			
    		//Display the delivery total, the artwork total and grand total.		
    		$curtain_price_total += $cur_v;		
    	}
    
    echo'<h3>Total for curtains: &pound '. number_format((float)$curtain_price_total, 2, '.', '').'</h3>';
    

    Relevant debugging info

    [curtain_basket] => Array                (                    [0] => Array                        (                            [Curtain Type] => Handmade triple pleat buckram heading                            [Track or pole width] => 500                            [Finished length of the curtain (drop)] => 500                            [Type of lining] => Blackout                            [Fullness] => Normal (double fullness)                            [Interlined] => No                            [Fabric width] => 139                            [The final quote] => 662.00                        )                    [1] => Array                        (                            [Curtain Type] => Handmade triple pleat buckram heading                            [Track or pole width] => 1000                            [Finished length of the curtain (drop)] => 1000                            [Type of lining] => Blackout                            [Fullness] => Normal (double fullness)                            [Interlined] => Yes                            [Fabric width] => 139                            [The final quote] => 2,615.70                        )                    [2] => Array                        (                            [Curtain Type] => Handmade triple pleat buckram heading                            [Track or pole width] => 5000                            [Finished length of the curtain (drop)] => 5000                            [Type of lining] => Blackout                            [Fullness] => Normal (double fullness)                            [Interlined] => No                            [Fabric width] => 139                            [The final quote] => 22,158.00                        )                )
    [curtain_price_total] => 686    [curtain_value] => Array        (            [Curtain Type] => Handmade triple pleat buckram heading            [Track or pole width] => 5000            [Finished length of the curtain (drop)] => 5000            [Type of lining] => Blackout            [Fullness] => Normal (double fullness)            [Interlined] => No            [Fabric width] => 139            [The final quote] => 22,158.00        )    [curtain_title] => 2    [cur_v] => 22,158.00    [cur_t] => The final quote

    It seemed to me at first glance to be a number formatting issue however the value of 'curtain_price_total' variable is already incorrect so the formatting seems to me to be irrelevant.

     

    It's a mystery to me and any help would be greatly appreciated.

    Cheers

    Paul

     

  4. No problem Larry.

     

    However, if you don't use localhost to test your email coding what do you use?

     

    My 'plan B' was to upload the code to a stand-alone page on my own live site and test it there. Obviously a bit more of a phaff because there's more chance of me winning a Nobel prize for PHP coding than my code working first time which means going backwards and forwards with FTPs.

     

    Cheers

    Paul

  5. Hi all,
    I've written the following very simple piece of code.

    <?php
    
    echo'
    <h1>Your emails</h1>
    ';
    
    $to = 'demoPHP@localhost.com';
    
    $subject = 'Email testing';
    
    $message = 'test';
    
    mail($to, $subject, $message);
    
    ?>
    

    The email doesn't arrive in Thunderbird using Mercury Mail in XAMPP on Windows.

     

    The text 'Your emails' appears in the browser so I know the file is being processed by PHP.

    I can send an email using Thunderbird from 'demoPHP@localhost.com' to 'demoPHP@localhost.com' and it arrives in the inbox OK, so I know that Mercury is configured OK in that it's sending emails.

    I've changed the php.ini file to the following:

     

    [mail function]
    ; For Win32 only.
    ; http://php.net/smtp
    SMTP = localhost
    ; http://php.net/smtp-port
    smtp_port = 25

    ; For Win32 only.
    ; http://php.net/sendmail-from
    ;sendmail_from = postmaster@localhost.com

     

    Does anyone have any ideas what I'm doing wrong. I'm actually running a Windows 64bit system. Would that make any difference? I'm referring to the fact that the php.ini file refers to 'Win32'.

     

    Thanks

    Paul

     

  6. Hi everyone,
    Hope you're all well. Have a look at the following seemingly very straightforward code from a file called 'orders/customer_details.php'.

    <form action="customer_details.php" method="post" />
    
    <input type="hidden" value="TRUE" name="submitted" />
    
    <input type="submit" value="Place your order" />
    </form>
    

    Unless I've been misunderstanding for years when I click on 'Place your order' the page should direct to 'customer_details.php' (itself) where there will eventually be other form fields, validation etc.

     

    However it redirects to 'orders/basket.php'. I have no idea why? I've looked through every line of code in 'customer_details.php' and the only time the word basket is mentioned is in comments or HTML. There is no redirection code to 'basket.php'. There is  file called 'basket/basket.php' but it's in a seperate directory to this redirection which is to orders/basket.php.

     

    I've tried everything I can think off. I've deleted the file and typed everything in manually. I've copied the code through Notepad in case there's anything odd in the bckground. I've bypassed Dreamweaver (because sometimes that has a mind of its own) and ran the url manually through XAMPP. Nothing seems to work. I can't believe something so easy doesn't work. I've loads of other forms on this site with exactly the same code and they work. Bizarre.

     

    Any help would be greatly appreciated before I go crackers!

     

    Cheers

    Paul

     

  7. Thanks for the advice. I'll give that a go tomorrow.

     

    One thing I find frustrating as a part-timer at this is how often I spend hours, if not days on a script and get 3/4 way through it and find it won't work because I've got the logic wrong. Do you do an outline like you have above before you start a script or or from experience can you just go from top to bottom?

     

    Paul

  8. Hiya,

    The hidden field is there.

     

    My confusion is that if there was a problem with the DB query then $row would not contain 25.00. If there was a problem with the form element then the $_POST  array would not contain H_H_allowance. One just doesn't seem to pick up the other.

     

    I've even just checked my spelling of allowance....make sure I didn't put allowence anywhere. Spelling is not my strong point, nor is PHP it appears!

     

    One of those days today.

     

    Cheers

    Paul

  9. Hiya,

    Really! I've tried that before and got myself in a right mess.

     

    If you had form 1 then if {isset($_POST['submitted'] etc. would apply to form 1. Then presumably you would validate that, assign it to variables and then load form 2 based on the answers in form 1.

     

    However how would you ensure that form 1 never reloaded? Would you need to nest forms within an if / else?

     

    I've always used the same approach. Code at the top with an {isset($_POST['submitted'] and the single form below. I must be getting old because it's never ossurred to me that more than one form can be on the same page.

     

    Is my thinking going in the right direction (the nesting within an if/else, not whether I'm getting old. I know that!)?

     

    Cheers

    Paul

  10. Hi all,
    As the topic title suggests I'm trying to populate a hidden form element with a number retrieved from a DB query. The hidden field appears in the post array but with no value. Yet the value appears in the debugging info.
     
    This is the query (it only returns one row):

    $q = "SELECT H_H_allowance FROM curtain_constants";
    
    $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
    
    if (mysqli_num_rows($r) == 0)
    {
    	//If there's nothing in the DB display this message
    	echo '<p>Oops, something\'s gone wrong. We\'re working on it, please would you try again later. Apologies.</p>';	
    }
    else
    {		
    	$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
    }
    
    

    This is the hidden form field:

    <input name="H_H_allowance" type="hidden" value="<?php $row['H_H_allowance'] ?>" />
    

    This is the relevant debugging info:

    [_POST] => Array        (            [fabric_width] => 139            [track_pole] =>             [drop] =>             [fullness] => 2            [vert_pattern_repeat] => 0            [hor_pattern_repeat] => 0            [pattern_match] => no            [H_H_allowance] =>             [submitted_curtains] => TRUE            [submit] => Get fabric quantity        )
    [row] => Array        (            [H_H_allowance] => 25.00        )

    Thanks once again.

    Paul

     

  11. Hiya,

    I've not posted a question for a while so I hope you're all well.

     

    My question is more of a general one as I can use sessions to solve the problem.

     

    I have 3 forms on 3 pages. The idea being to ask the user for information and pass that information in the url to the next page and then pass the same information plus some more attained from the form onto the 3rd page. I know that I can use sessions for this however I would like to understand the $_GET array a bit more because I feel that I should be able to do this without sessions.

     

    The problem I'm having is getting the information into the url for the subsequent pages. I can pass information from the first form and when it redirects the user to the second form the $_GET array contains the information. So far so good! The second form uses the $_POST array because it needs to validate the additional information. When the form is submitted the $_GET array 'empties'. I understand why that's the case.

     

    So I tried the following in order to use the information in the $_GET array on that second page:

    1. Assigning the $_GET to a variable. However when the form is submitted it tries to do it again and there's an error because there's nothing in the $_GET array.

    2. Assigning the values in the $_GET array to a cookie. However the information is not available until the page reloads.

     

    In a nutshell how do I get GET information back into the url so as to pass it onto other pages.

     

    Cheers

    Paul

     

  12. Derek,

    The problem I had was that my paths were incorrect, have a look at the paths in your config file.

     

    Also look at the connect script itself, has the DB the same name in live etc. I also seem to remember getting myself a bit confused between my account password with my host and my DB password with my host.

     

    Otherwise please post the error messages you get when you try to connect.

     

    Cheers

    Paul

  13. Hi all,

     

    Abigail. How does shared SSL work? My understanding of SSL is that it was in the exact name of the website to give people the security that they were dealing with the people they thought they were dealing with? My hosting company supplies SSL from £10.

     

    Also, as per my earlier question does SSL slow down a website or have any detrimental effects?

     

    Cheers

    Paul

  14. Hi everyone,

    I'm going to add another 2 cents worth in that I agree with Antonio, I've never used SSL on login scripts etc, I was only going to use it on actual e-commerce financial transaction pages.

     

    Saying that, a question. If, like I will be shortly, you purchase an SSL certificate for an e-commerce site my understanding is that you have it for the whole site. So, in that case, are there any disadvangaes to using it on more pages, such as logins, than you normally would? I'm basically saying, don't buy one unneccessarily, but if you have one anyway.

     

    Here's an article about them that I found useful:

     

    http://webnet77.com/SSL-certificates.html

     

    Cheers

    Paul

  15. Derek,

    My host tells me to put everything in the public_html directory.

     

    So in this directory goes the various php pages, such as index.php, contact.php etc.

     

    Also within this directory I have my includes folder and my images folder. My includes folder contains the header, footer, config file, CSS files etc.

     

    I have placed my connect scripts one step above the public_html directory (where your host says that they are not viewable by anyone). I asked my host what the direct path to this location was, I believe that's a more secure way of doing it than a relative link. Your host may replace 'public_html' with another designation but the structure is otherwise the same.

     

    I beleive that this is the best way to do it from a security point of view but if anyone out there has a better way then please holler.

     

    Cheers

    Paul

  16. Derekd,

    Hi. I've put sites live in as much as I've put them into my test area on my own website so that clients can test them.

     

    The things I've had to look out for when doing this was error reporting and file paths. I have error reporting on 'localhost' set so that it shows me everything, not what you want in a live environment. Also, depending on how you've set up your config file etc. check to see where your file paths are pointing, or you may find that you DB connection doesn't work, for example. Finally if you're transferring DBs and tables MySQL has a good export / import capability rather than typing them back up again. I like cPanel, I think it's OK. Don't know what WHM is. Good luck, and if it doesn't work first time, don't panic, just work through it one step at a time.

     

    This is my first atempt at a forum 'answer' so if anyone else has any further points please chip in.

     

    Cheers

    Paul

    • Upvote 2
  17. Wow! This is marvellous, thanks for your work on this. This morning I had a good read, and then another good read. Then I took myself out for a walk to clear my aching head and then had another good read!

     

    I think I've got most of it OK. The fact that I don't have all of it says more, of course, about my powers of reasoning that about your very clear explanation.

     

    My thoughts as I've gone through it.

     

    1. The fact that the subquery returns no values, only TRUE or FALSE never occurred to me. Seems obvious now you've explained it but my original query would never have worked because I was expected the outer query to check on actual values returned from the subquery.

     

    2. I can see clearly now why an alias is needed for some but not all.

     

    3. Your point about correlated and non-correlated is an important one to remember, so as to get the order of the query correct. However I'm not clear on the distinction between the two. You started with this shortened query, which you stated is a non-correlated one.

     

    SELECT aid FROM cat_artist AS c1 WHERE EXISTS (SELECT 1 FROM cat_artist AS c2 WHERE cid = 11);

     

    You then moved onto this query, which becomes a correlated one:

     

    SELECT aid FROM cat_artist AS c1 WHERE EXISTS (SELECT 1 FROM cat_artist AS c2 WHERE cid = 11 AND c1.aid = c2.aid);

     

    Now both subqueries refer to cat_artist, the table used in the outer query. That appears to me to satisfy the definition of a correlated, as per

     

    'When a subquery references the table in the outer query, the subquery is called a correlated subquery. The opposite (i.e., a subquery that does not reference the outer query) is called a noncorrelated query.'

     

    I'm sorry, I'm missing something. This part seems too important not to understand as it changes the order of the query.

     

    Other than that above I can follow everything you have said. Your points about the 'c1.aid = c2.aid condition' are very clever, not sure my brain could make that leap of logic quite yet!

     

    Thanks for your time on this, it is really appreciated.

     

    Paul

×
×
  • Create New...