Solved

reduce POST value by 75

Posted on 2008-09-30
6
179 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
  • 3
  • 3
6 Comments
 
LVL 109

Expert Comment

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

Accepted Solution

by:
Ray Paseur earned 500 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Closing Comment

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

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

778 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