Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    852
    Thanks
    173
    Thanked 94 Times in 94 Posts

    do these nested IFs make any sense

    Hi all

    I'm trying to validate against paypal isent nfo BUT as usual I'm lost in my logic and if statements.

    Does this make any sense?

    How far out am I??

    Any help greatly welcomed. Do I need to rearrange?

    LT


    PHP Code:
        if (strcmp ($res"VERIFIED") == 0) {

                
    // check the payment_status is Completed
                // WHAT TO DO IF ONE OF THESE IS INCORRECT???? error notify??
            
    if (($payment_status == ‘Completed’) && 
                (
    $receiver_email == $mypaypalemail) && // receiver_email === yr account email 
                
    ($mc_gross == $amount_required ) && //payment === yr reqd payment 
                
    ($mc_currency == $mycurrency)) {
        
                
    ///////////////////////////////////////////////////////////////
                //create MySQL connection
                
    $Connect = @mysql_connect($DB_Server$DB_Username$DB_Password)
                or die(
    "Couldn't connect to MySQL:<br>" mysql_error() . "<br>" mysql_errno());

                
    //select database
                
    $Db = @mysql_select_db($DB_DBName$Connect)
                or die(
    "Couldn't select database:<br>" mysql_error(). "<br>" mysql_errno());
                
    //////////////////////////////////

                //check if transaction ID has been processed before
                // WHAT TO DO IF PROCESSED BEFORE???? error notify??
                
    $checkquery "SELECT txn_id FROM users WHERE txn_id='".$txn_id."'";
                
    $result mysql_query($checkquery) or die("Duplicate txn id check query failed:<br>" mysql_error() . "<br>" // mysql_errno());
                
    $nm mysql_num_rows($result);
                if (
    $nm == 0) {
                    
    mysql_query("INSERT INTO users (CODE);  

                    //////////////////////////////////////
                    // PAYMENT VALIDATED & VERIFIED!  
        
                    $mail_From = "
    Fromme@mybiz.com";
                    // all mail details
                    mail($mail_To, $mail_Subject,  $message . "
    nn" . $mail_From, $headers);
                } else{
                    // notify myself??
                }
            }else {
                // error notify person and myself ??
            }
        }

    else if (strcmp ($res, "
    INVALID") == 0) 
    Last edited by low tech; 11-08-2010 at 01:25 AM.

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    And this is why colors are good

    PHP Code:
    mysql_query("INSERT INTO users (CODE); 
    Is it safe to assume CODE is actually something else? Because if not, that's a big bug right there... plus, the quote isn't closed nor the function closed. Also, any reason you put every comparison in parens? Its not necessary, and I know for myself, only muddles the issues at hand.

  • #3
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    852
    Thanks
    173
    Thanked 94 Times in 94 Posts
    Hi Keleth
    Thanks fo reply

    Is it safe to assume CODE is actually something else?
    Yep this part of code is done tried and tested --- so I just cut it short here --- no need to waste time to look at it.

    Its all the part above it that I'm trying to sort out ---- I don't know if my logic is ok and if my nesting is correct ---

    Also, any reason you put every comparison in parens?
    No reason other than I'm new.

    Are my 'else' positions in the right place ti deal with error if something returns false --- ie if the check id returns duplicate --- then I should jump to error right???

    LT

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    As far as I can tell, yah, the nesting looks good. You indented, which is a good way to make sure nesting is working properly. The only thing I'd say to do, at the end you have "else if". Change that to "elseif". By doing "else if", you're summoning two commands... else and if. By doing "elseif", you do one command. They do the same thing really, and it won't affect page load time unless you have thousands upon thousands of lines of code, but its just good habit.

    I guess if you're just looking for advice on your code, any reason you have "nn" in the middle of your mail code?

  • #5
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    852
    Thanks
    173
    Thanked 94 Times in 94 Posts
    Thanks Keleth

    nice feedback

    I'll chenge the else if to elseif ---- never knew there was a difference -- although from looking at other scripts I had noticed the use --- just figured must be same either way.

    and the nn in original script is backslash n ----- new line yeh? It works when mail is sent anyway.

    So if any "if" conditio(s) fail --- then I should write what to do in the appropiate corrosponding "else" position ---- ie send mail either to myself and or person making payment to noify error???

    my first time to try anything like this, so sorry for stupid questions.

    LT
    Last edited by low tech; 11-07-2010 at 04:39 AM.

  • #6
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Yah, if the "if" is essential to the flow, then you should have an else, which both feeds out an error to the user and to yourself (by whatever way you want, a mail to you, store to a file, etc).

  • Users who have thanked Keleth for this post:

    low tech (11-07-2010)

  • #7
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    852
    Thanks
    173
    Thanked 94 Times in 94 Posts
    Hi Keleth

    thanks of rall the help so far --- magic


    I know I can do this

    example:

    PHP Code:
    $mail_From "From: me@mybiz.com";
    $mail_To "admin@englishfreaks.com";
    $mail_Subject "VERIFIED IPN";

    $message "  
     
    Thank you for registering   "
    ;  

    $headers 'From:xyz@abc.com' "\r\n"
    mail($mail_To$mail_Subject,  $message "\n\n" $mail_From$headers);

    BUT I have this var set earlier
    $notify_email = "admin@mysite.com";

    so can I do this in my else part

    PHP Code:
    else {
        
    // DUPLICATE: error notify
    mail($notify_email"VERIFIED DUPLICATED TRANSACTION""$user_email\n $result\n $payment_status\n $receiver_email\n $mc_gross\n $mc_currency");
            } 
    IF I can thenI also want to send a mail to user--- do I just make two?

    PHP Code:
    mail ($notify_emailabcetc etc );
    mail ($user_emailabchave a message in a var and put var here?? ); 
    LT

  • #8
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    Quote Originally Posted by low tech View Post

    IF I can thenI also want to send a mail to user--- do I just make two?

    PHP Code:
    mail ($notify_emailabcetc etc );
    mail ($user_emailabchave a message in a var and put var here?? ); 
    Yes, you can run any number of mail function.

  • #9
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    852
    Thanks
    173
    Thanked 94 Times in 94 Posts
    Hi Poyzn

    excellent

    time for the big test then:-)

    IS this idea correct then --- should I store the body massage in a var and place as in code???

    PHP Code:
    mail ($user_emailabc, [COLOR="Red"]have a message in a var and put var here?? [/COLOR]); 
    LT
    ps
    Just thinking how the format will look from users end

    for myself is ok.

  • #10
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    You can even store your messages in html-rich format. Like this:
    PHP Code:
    $message '<h1>Hello,</h1><p>Thank you for making a donation ...</p><p>LT</p>'
    but then you should pass next header to mail function:
    PHP Code:
    $headers .= 'Content-Type: text/html; charset=utf-8'."\r\n" // set your charset
    mail($to$subject$message$headers); 
    Last edited by poyzn; 11-07-2010 at 07:26 AM.

  • Users who have thanked poyzn for this post:

    low tech (11-07-2010)

  • #11
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    852
    Thanks
    173
    Thanked 94 Times in 94 Posts
    ahahaha

    Yeh cool ---

    i'll try that once i get past my current testing point --

    magic:-)

    LT


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •