Page 1 of 1

Post Variables with commma

Posted: Tue Dec 16, 2003 9:06 am
by timclaason
I have a page where a user posts a dollar amount. However, I had always assumed the user would enter a dollar amount without commas, decimal places, or dollar signs...I was wrong.

How can I check there input and remove any of these rogue characters?

I am using the post method on the frontpage form. Thanks

For instance...suppose they enter: $200,000.00
I want a variable to just take the integer value: $input=200000;

Posted: Tue Dec 16, 2003 9:10 am
by malcolmboston
not sure what you want, so heres some ideas

$_POST['money'];

$_SESSION['money';

http://uk.php.net/setcookieset cookie() function

if your having a problem with certain values not passing use a . before them

like .$_SESSION, this as i am reliably told, exits a string to go to a variable and back again, you can find complex explanations on google or here

hope this gives you some ideas

Posted: Tue Dec 16, 2003 9:15 am
by JayBird
try this

Code: Select all

$money_without_commas = str_replace ( ",", "", $_POST['money']);
Mark

Posted: Tue Dec 16, 2003 9:18 am
by timclaason
Will this be a problem if the user enters the value without any commas?

Posted: Tue Dec 16, 2003 9:19 am
by JayBird
no, will be fine

Posted: Tue Dec 16, 2003 9:19 am
by malcolmboston
ask mysql to strip it, or javascript.

PHP can probably do it as well