drumhrd Posted January 26, 2010 Share Posted January 26, 2010 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 } Quote Link to comment https://forums.phpfreaks.com/topic/189821-new-quick-help-with-string-comparison/ Share on other sites More sharing options...
drumhrd Posted January 26, 2010 Author Share Posted January 26, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/189821-new-quick-help-with-string-comparison/#findComment-1001720 Share on other sites More sharing options...
RussellReal Posted January 26, 2010 Share Posted January 26, 2010 a string 0 is different from a numeric 0 "0" is true, 0 is false.. remove it from the quotes strcmp($_REQUEST['mc_gross'],$total) != "0" change to strcmp($_REQUEST['mc_gross'],$total) != 0 Quote Link to comment https://forums.phpfreaks.com/topic/189821-new-quick-help-with-string-comparison/#findComment-1001721 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.