Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 182597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:58:04+00:00 2026-05-11T14:58:04+00:00

I put a check in a script that makes sure a total is correct.

  • 0

I put a check in a script that makes sure a total is correct. What it does is looks at the total as it is stored in the database and then using other variables, calculates what the total should be.

If these two values – the stored total and the calculated total – are not equal, it’s a problem so I want it to send an email alert.

Here’s the snippet of the code I use to do this:

$storedTotal     = $row['total']; # Pulls from a varchar field in the database $calculatedTotal = $subtotal + $tax + $shipping - $deduct;  # Make sure the stored total equals what it should (the calculated total) if($storedTotal != $calculatedTotal) {     # Send an alert     mail('admin@domain.com','Total check fail','Stored total:$storedTotal \n\n Calculated total:$calculatedTotal \n\n'); } 

It seems very simple, however, I repeatedly get emails from it that looks like this:

Stored total:23.40  Calculated total:23.40 

As you can see, the two values appear the same.

Can anyone see any reason why they’re not showing as equal? I’m not using a strict equality check so it shouldn’t be getting tripped up on types.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T14:58:04+00:00Added an answer on May 11, 2026 at 2:58 pm

    Try converting and rounding before you compare them:

    $storedTotal        = round(floatval($storedTotal), 2); $calculatedTotal    = round(floatval($calculatedTotal), 2);  if ($storedTotal != calculatedTotal) { ... 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my login script I have put a checkbox that people can check if
Put it another way: what code have you written that cannot fail. I'm interested
We put all of our unit tests in their own projects. We find that
Simply put, is there a way to create a 2D javascript array using similar
To put it simple, there's a simple java swing app that consists of JFrame
I have some code that someone wants to put on their site. Here is
I want to retrieve the user's location and then show a link that points
My main problem is where does database go? The project will be on SVN
I am working on an authorization script that checks for user name, password and
Here is the script that i wrote and it has weird syntax error at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.