• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 185
  • Last Modified:

reduce POST value by 75

Hello,

In the below code I am checking if a post value exists, if it does I want to reduce that amount by 75.00, is teh code below correct?

Thank you.
if (isset($_POST['amount']))
	{
	$_POST['amount']= ($_POST['amount']-'75.00');
	}

Open in new window

0
vrmetro
Asked:
vrmetro
  • 3
  • 3
1 Solution
 
Ray PaseurCommented:
You should remove the quotes from '75.00'
0
 
Ray PaseurCommented:
I might do something like this.  What edits you would do would depend on what final values are acceptable for your application.
if (isset($_POST['amount']))
{
        $amount	= trim(ereg_replace("[^0-9\.\-]", "", $_POST['amount']));
        $amount = $amount - 75.00;
        $_POST['amount']= $amount; // OR JUST USE $AMOUNT
}

Open in new window

0
 
vrmetroAuthor Commented:
What does this part do?

ereg_replace("[^0-9\.\-]",
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
vrmetroAuthor Commented:
what does ereg_replace("[^0-9\.\-]",  do?
0
 
Ray PaseurCommented:
Hi,vrmetro:Thanks for the points!  That ereg statement discards everything except the numerals, the decimal point and the minus sign.  You would not get a meaningful answer if $_POST had "$79.00" in the field - unless you made some edits to control for the kind of data that work with arithmetic. ~Ray
0
 
vrmetroAuthor Commented:
thanks Ray, much appreciated.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now