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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    852
    Thanks
    173
    Thanked 94 Times in 94 Posts

    checking for duplicate problem

    Hi all

    I want to check for duplicates, if exists I write an error BUT

    this works

    PHP Code:
    $checkquery "SELECT user_email FROM users WHERE user_email='".$user_email."'"


    BUT I would like to check two areas txn_id, user_email

    and when I do this it doesn't work even tho I send a duplicate

    PHP Code:
    $checkquery "SELECT txn_id, user_email FROM users WHERE 

    txn_id='"
    .$txn_id."', user_email='".$user_email."'"
    what have I done wrong -- logic?


    any help very much appreciated
    LT

    this is what I have by the way
    PHP Code:
    $checkquery "SELECT user_email FROM users WHERE user_email='".$user_email."'";
                
    $the_result mysql_query($checkquery$Connect) or die("Duplicate txn id check query failed:<br>" mysql_error() . "<br>" mysql_errno());
                
    $nm mysql_num_rows($the_result);
                if (
    $nm == 0) { DO SMTHG 
    Last edited by low tech; 12-03-2010 at 09:26 AM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,855
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    What's txn_id?
    $the_result = mysql_query($checkquery, $Connect) or die("Duplicate txn id check query failed:<br>" . mysql_error() . "<br>" . mysql_errno());
    Don't you get any errors for your query?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

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

    txn_id is just number eg 017856342

    and I don't get error ---- I just deleted my log and tried again to see if it generated a new error log --- but nothing.

    I can check one or the other but when I put them both together I get zero.

    If I do one and send a duplicate it errors and I get a mail to myself.


    LT

  • #4
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    Two things:

    1. echo($checkquery) so we can see the actual SQL being passed to mysql_query.
    2. Use AND, not ","
    3. Please sanitise your inputs:

    PHP Code:
    $checkquery "SELECT txn_id, user_email FROM users WHERE  

    txn_id='"
    .mysql_real_escape_string($txn_id)."' AND user_email='".mysql_real_escape_string($user_email)."'"
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

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

    I tried this but nothing as yet --- and no error log:-(

    I think I've put the echo wrong too ---- not sure what that does actually --- where will it echo to? Anyway --- back later --- the misses iz giving me hell hahahhahaa


    PHP Code:
    $checkquery "SELECT txn_id, user_email FROM users WHERE  txn_id='".mysql_real_escape_string($txn_id)."' AND user_email='".mysql_real_escape_string($user_email)."'"
                echo(
    $checkquery); 
                
    $result mysql_query($checkquery$Connect) or die("Duplicate txn id check query failed:<br>" mysql_error() . "<br>" mysql_errno());
                
    $nm mysql_num_rows($result);
                if (
    $nm == 0
    LT

  • #6
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    If you run the script from a browser, the echo will go to the browser. If you run the script from the shell/terminal/ssh, it will go into the shell/terminal/ssh window. You should be getting *something* displayed from that echo...
    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

    Ok

    the script is an IPN (instant payment notification) script so its just on my server and I send info from paypal (test area)

    I tried to access script via webpage --- ie I put address in browser and the page comes up blank (I guess that's expected)
    I get an INVALID IPN sent to my mail account.

    I have no idea how to run from the shell/terminal/ssh (never had to do it and my knowledge doesn't go that far)

    so far I have these errors (but they don't seem to stop the script working)

    PHP Code:
    mysql_free_result(): supplied argument is not a valid MySQL result resource
    mysql_close
    (): supplied argument is not a valid MySQL-Link resource 
    I guess errors related to here


    PHP Code:
    $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
                // on error notify
                
    $checkquery "SELECT txn_id, user_email FROM users WHERE  txn_id='".mysql_real_escape_string($txn_id)."' AND user_email='".mysql_real_escape_string($user_email)."'"
                echo(
    $checkquery); 
                
    $result mysql_query($checkquery$Connect) or die("Duplicate txn id check query failed:<br>" mysql_error() . "<br>" mysql_errno());
                
    $nm mysql_num_rows($result);
                if (
    $nm == 0

    I have this at end of my script

    PHP Code:
    mysql_free_result($result);
    mysql_close($Connect);
    fclose ($fp); 
    LT

  • #8
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    Don't worry about mysql_free_result or mysql_close - we're in the modern age of garbage collecting languages, and all the poor coding practices that brings. Go progress! *cough*

    IPN: The curse of debuggers everywhere.

    Use file_put_contents('debug.txt', $checkquery); and view the debug.txt
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

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

    i've tried putting a log file --- I thought it would write the contents of $checkquery -- but it didn't

    echo($checkquery);
    fwrite($log, '".$checkquery."');

    I got this is log file hahahhahhaa

    ipn - Dec 02 2010 12:16:02
    ".$checkquery."

    How do I get it to echo $checkquery into log file???

    LT

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

    ok


    I got this is debug.txt


    SELECT txn_id, user_email FROM users WHERE txn_id='017856342' AND user_email='expirydate@paypalsandbox.com'


    the email exists in my DB so it should fail and send out mail (but it doesn;t when used together with txn_id)

    LT

    this is my query

    PHP Code:
    $checkquery "SELECT txn_id, user_email FROM users WHERE  txn_id='".mysql_real_escape_string($txn_id)."' AND user_email='".mysql_real_escape_string($user_email)."'"
                echo(
    $checkquery);
                
    //fwrite($log, '".$checkquery."'); 
                
    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());
                
    $nm mysql_num_rows($result);
                if (
    $nm == 0
    Last edited by low tech; 12-02-2010 at 12:29 PM.

  • #11
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    I think you could do with learning a little about quotes. Firstly, a variable doesn't need to be quoted if it's just the variable you want.

    PHP Code:
    fwrite($log$checkquery); 
    Secondly, there's a difference between ' and ":

    PHP Code:
    $hello "there";
    $var '$hello'// $var is now $hello
    $var "$hello"// $var is now there 
    PHP only replaces variables with their contents (variable substitution) with double quotes ("). Single quotes (') are not processed at all (except for \').

    If you want to write $checkquery with quotes into the log, do one of these:

    PHP Code:
    // " quoted
    fwrite($log'"'.$checkquery.'"');
    fwrite($log"\"$checkquery\"");
    // ' quoted
    fwrite($log"'$checkquery'");
    fwrite($log'\''.$checkquery.'\''); 
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

  • #12
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    To save a little code and keep it tidy, instead of:

    PHP Code:
    $nm mysql_num_rows($result); 
    if (
    $nm == 0
    Do:

    PHP Code:
    if (!mysql_fetch_array($result)) { 
    Back to the topic at hand: Do you have phpmyadmin or access to run the mysql client from the terminal? What happens when you run that SQL through one of those?
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

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

    Yeh you are right --- I'm lost with quotes along with the rest of php (pretty hard programming) :-)

    I'm no coder for sure hahahhahaa

    anyway if ' ' are not processed at all --- why use them???

    I'm very new so it's all uphill.

    LT
    ps
    did yo see post #10 I think I posted as you did
    forget this I see you did --- i'm out sequence with posting

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

    PHP Code:
    Do you have phpmyadmin or access to run the mysql client from the terminal
    yeh it's my website ----- just no idea how to do that:-(


    it's a bit weird that it will work with one or the other but not both, don;t you think?

    LT

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


    I wanna thank you for having a go at this with me ---- thanks a lot really


    I'll take another crack it tomorrow I think ----- maybe there is another way I can perform the checks ---- sepeperately maybe? I dunno.

    LT

    late n tired


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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