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 13 of 13
  1. #1
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    852
    Thanks
    173
    Thanked 94 Times in 94 Posts

    How do I get the 'result' of this query into my error notify mail??

    Hello everyone

    How do I get the 'result' of this query into my error notify mail??

    It will either fail on one or both --- (or none) --- but if fail how do I get the reesult into my error report to myself??

    I tried puuting $result in but that just gives me Resource id #3

    and this gives me the query $checkquery.


    PHP Code:
                $checkquery "SELECT txn_id, user_email FROM users WHERE  txn_id='".mysql_real_escape_string($txn_id)."' OR user_email='".mysql_real_escape_string($user_email)."'"
                
    // file_put_contents('debug.txt', $checkquery);
                
    $result mysql_query($checkquery$Connect) or die("Duplicate txn id check query failed:<br>" mysql_error() . "<br>" mysql_errno());
                    if (!
    mysql_fetch_array($result)) { do smthg
    PHP Code:
    else{
                    
    // DUPLICATE: error notify 
                    
    mail($notify_email"VERIFIED DUPLICATED TRANSACTION or EMAIL"); } 

    LT

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    In your mind, what is a "fail"? Do you mean the query returns nothing? Or there's a duplicate txn_id?

    The function mysql_fetch_array() returns an array of column values if a row is found, and FALSE if a row is not found. So if it returns FALSE, that means there is no data fetched so you can't display any fetched data.

    $result stores what PHP calls a query resource. There's no data from the query stored in $result; that's why you call mysql_fetch_array().

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

    not sure if what i'm thinking to do is technically correct / possible or not but


    Yeh in my mind 'fail' is it finds a duplicate ---- that means I send an error to myself but I'm thinkng---- I would like to include the duplicate(s) that it found (which will be one or two rows) in my error report so I will know it found duplicate txn_id or duplicate email or both

    but I don't know how to get that:-(

    does that make sense

    if nothing is found -- zero rows --- it goes on to insert stuff into DB


    LT

    $result stores what PHP calls a query resource.
    hahah yeh I found that out by trying to include $result which at the time didn't make sense but I kinda guessed
    Last edited by low tech; 12-03-2010 at 06:31 AM.

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    So if a fail is finding more than one row with the same txn_id, your query should be

    Code:
    SELECT COUNT(*)
    FROM users
    WHERE txn_id = $txn_id
    Then see if the value fetched is > 1.

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

    I think a fail is finding more than zero --- ie if it finds one its a fail ---- There should either be none or one ---- if one already exists in DB then its a fail.

    BUT my problem is when it fails --- it means it found one (at most two)--- how do I get that one(or two) into my error report ??


    Now the query does work -- it does fail if I send duplicate email or txn_id or both.

    So example if I send duplicate txn_id 12235678

    and it's already in DB

    it will fail and send myself a notice but I want my error report to include what it found in DB ie duplicate 12345678 (or email or both)

    it seems to make sense to me anyway hhaha



    LT

  • #6
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    Well, as abduraooft pointed out in the last thread I helped you with: If you create a joint unique index for txn_id and user_email, there can't be any duplicates. Perhaps that's a better way to go?

    Edit: I just read your other thread. Nevermind

    I'll see about taking a look later if no one else has - I have a busy day today.
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

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

    Yes as I said in the other post your solution worked very well. Thank you:-)

    I just thought I could help myself by reporting to myself what duplicate had been found.

    ie
    txn_id
    user_email
    or
    both

    In truth they are unlikely(but not impossble) and since i'm very interested to learn and this is a real life situation ie mine:-) why not?


    I can only think one stage at a time so everythign is changing as I face / discover next problem:-(


    LT

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

    Well I've tried and tried and i've read stuff but nah I can't figure it out

    I used this in my script

    while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    foreach ($line as $col_value) {
    echo $col_value ; // i changed this line around also but got nothing:-(
    }
    }

    and tried to put $col_value in my error mail hahhahhaha nah didn't work

    and i tried load of other crazy ways too hahahaa

    so if anybody has any idea of how I should try to do this

    i'm very interested and would love the help

    I'd even be interested to know if what i'm trying to do is silly:-)

    LT
    ps:-)smile

  • #9
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    What happens when you place your query into PhpMyAdmin and run it?

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

    don't laugh i'm trying hahhahaha

    This query put into PhpMyAdmin

    PHP Code:
    SELECT txn_iduser_email FROM users WHERE  txn_id='907856342' AND user_email='expirydate@paypalsandbox.com' 
    returns this as expected

    PHP Code:
    table
    txn_id  user_email  
    907856342 expirydate
    @paypalsandbox.com 
    BUT if I try to add on this

    PHP Code:
    while ($line mysql_fetch_array($resultMYSQL_ASSOC)) {
    foreach (
    $line as $col_value) {
    echo 
    $col_value // i changed this line around also but got nothing:-(
    }

    it shouts syntax errors at me ---- also expected hahahhaa

    since my real query also has this line

    PHP Code:
    $result mysql_query($checkquery$Connect) or die("Duplicate txn id check query failed:<br>" mysql_error() . "<br>" mysql_errno()); 
    and I think the while loop

    or this (which I also playing with)

    PHP Code:
    $num_rows mysql_num_rows($result); 
    which should probably be below that line BUT if put that line in PhpMyAdmin of course it goes nuts again hahahahhahhaa

    what should I be trying to do??

    There must be a way to get that row information out of DB and into my error report.

    LT

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

    ok with this query (which will give me duplicate)

    PHP Code:
                $checkquery "SELECT txn_id, user_email FROM users WHERE  txn_id='".mysql_real_escape_string($txn_id)."' OR user_email='".mysql_real_escape_string($user_email)."'"
                
    // file_put_contents('debug.txt', $checkquery);
                
    $result mysql_query($checkquery$Connect) or die("Duplicate txn id check query failed:<br>" mysql_error() . "<br>" mysql_errno());
                
                
    $num_rows mysql_num_rows($result);
                

                    if (!
    mysql_fetch_array($result)) 

    IN m else Ihave this

    PHP Code:
    else{
                    
    // DUPLICATE: error notify 
                    
    mail($notify_email"VERIFIED DUPLICATED TRANSACTION or EMAIL""$num_rows Rows\n\n 
    and in my error email I get this


    1 Rows



    BUT I don;t get the DETAILS of that row??????

    ok I don't get it

    :-(

    LT

  • #12
    New Coder
    Join Date
    Nov 2010
    Posts
    15
    Thanks
    0
    Thanked 1 Time in 1 Post
    I'm not sure I understand completely, but your query seems like it will die when it finds duplicates instead of returning all the information you need. And if you find more then one duplicate then I didn't see any way of returning that information at all. Try this, you may have to edit it a little:

    PHP Code:
    <?php
    $checkquery 
    "SELECT * FROM users where txn_id='".mysql_real_escape_string($txn_id)."' OR user_email='".mysql_real_escape_string($user_email)."'";
        
    $result=mysql_query($checkquery,$Connect) or die(mysql_error());
            
    $num_rowsmysql_num_rows($result);
            
            if(
    $num_rows !=0){
                
    $duplicates=mysql_fetch_assoc($result);
                                
    $content="These are your list of duplicates:\n\n\n";
                    foreach(
    $duplicates as $duplicate){
                        
    $content .= "Duplicate Txn ID: " $duplicate['txn_id'] . "\n\n";
                        
    $content .= "Duplicate Email Addresses: " $duplicate['user_email'] . "\n\n";
                    }
            
                    
    mail($notify_email,"Duplicates Found",$content);
            }else{
                
    //Whatever you do upon success.
            
    }
    ?>
    Last edited by syncupsolutions; 12-04-2010 at 10:40 AM.

  • Users who have thanked syncupsolutions for this post:

    low tech (12-04-2010)

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

    oh wow

    amazing effort

    thanks a million

    can't play around with it now, but will definately try it asap

    LT

    ps I have lots n lots of errors because i'm just learning as I go --- but it's ok:-)
    Last edited by low tech; 12-04-2010 at 01:53 PM.


  •  

    Posting Permissions

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