Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

reduce POST value by 75

Posted on 2008-09-30
6
Medium Priority
?
184 Views
Last Modified: 2012-05-05
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
Comment
Question by:vrmetro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 22606360
You should remove the quotes from '75.00'
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 22606407
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
 

Author Comment

by:vrmetro
ID: 22606687
What does this part do?

ereg_replace("[^0-9\.\-]",
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Closing Comment

by:vrmetro
ID: 31501584
what does ereg_replace("[^0-9\.\-]",  do?
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 22606978
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
 

Author Comment

by:vrmetro
ID: 22607536
thanks Ray, much appreciated.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question