Jump to content

new quick help with string comparison


drumhrd

Recommended Posts

Ok so not sure why this isn't working.

 

if my $total,$plusone, or $minusone vars == to the $_REQUEST['mc_gross'] I want to do some processsing.

 

However my code isn't working.

 

Notice the file logging I am doing.

 

 

Here is output from my log file

 

emails match

total is 10.98

compare is 0

totals don't match

mc_gross was 10.98

total was 10.98

plus one was 10.99

minus one was 10.97

 

At first I didn't use strcmp but thought maybe somehow the strings weren't matching.

 

notice strcmp returns a "0"..why is this code firing on my if and not skipping to my else???

 

 

 

 //make sure the order totals match
                            $test = $test . " emails match\n";
                            $total = $_REQUEST['mc_shipping'] + $txn_paid_total['order_total'];
                            $test = $test . " total is ".$total . "\n";
                            //since the getsplitship function rounds to the nearest penny
                            //set variables to check for +/- 1 penny
                            
                            $plusone = $total + .01;
                            $minusone = $total - .01;
                            
                            if (strcmp($_REQUEST['mc_gross'],$total) != "0" || strcmp($_REQUEST['mc_gross'],$plusone) != "0" || strcmp($_REQUEST['mc_gross'],$minusone) != "0"){
                            //if ($_REQUEST['mc_gross'] != $total || $_REQUEST['mc_gross'] != $plusone || $_REQUEST['mc_gross'] != $minusone){
                                //assume fraud write to file
                                //figure out the best way to log the data
                                $compare = strcmp($_REQUEST['mc_gross'],$total);
                                $test = $test . " compare is " .$compare."\n";
                                $test = $test . " totals don't match\n";
                                $test = $test . " mc_gross was ".$_REQUEST['mc_gross'] ."\n";
                                $test = $test . " total was ".$total ."\n";
                                $test = $test . " plus one was ".$plusone ."\n";
                                $test = $test . " minus one was ".$minusone ."\n";
                                $myfile = '/var/www/test.log';
                            $fh = fopen($myfile, 'a') or die ("can't open file - " . $myfile);
                            fwrite($fh, $test);
                            fclose($fh);
                            exit;
                                
                            }

else{
//processing code omitted

}


Link to comment
Share on other sites

I attempted to change my code around..still no luck..

 

if ($_REQUEST['mc_gross'] == $total || $_REQUEST['mc_gross'] == $plusone || $_REQUEST['mc_gross'] == $minusone){
                                 
            //processing code omitted.

                            }
                            else{
                               //assume fraud write to file
                                //figure out the best way to log the data
                                $compare = strcmp($_REQUEST[mc_gross],$total);
                                $test = $test . " compare is " .$compare."\n";
                                $test = $test . " totals don't match\n";
                                $test = $test . " mc_gross was ".$_REQUEST['mc_gross'] ."\n";
                                $test = $test . " total was ".$total ."\n";
                                $test = $test . " plus one was ".$plusone ."\n";
                                $test = $test . " minus one was ".$minusone ."\n";
                                $myfile = '/var/www/test.log';
                            $fh = fopen($myfile, 'a') or die ("can't open file - " . $myfile);
                            fwrite($fh, $test);
                            fclose($fh);
                            exit;
                            
                            }

 

I don't know why they aren't matching

 

//from log file

 

emails match

total is 19.99

compare is 0

totals don't match

mc_gross was 19.99

total was 19.99

plus one was 20

minus one was 19.98

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.