Skip to main content
Participant
March 1, 2007
Question

Replace comma with dot

  • March 1, 2007
  • 1 reply
  • 373 views
I have an update form to update an amount. The amount is stored in a database as a decimal 10,2. When I request the update form I get the amount as 1000,00 due to the fromatting I'm using. When I alter the amount in 1000,55 and send the input then everything before the comma gets updated and all that comes after is gone. If I type a dot instead of the comma then the amount is updated correctly. How can I do the update statement so that the comma gets replaced by a dot?

Update statement:

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "frmBudget")) {
$updateSQL = sprintf("UPDATE tbl_budgets SET budget=%s WHERE schoolid=%s",
GetSQLValueString($_POST['budget'], "double"),
GetSQLValueString($_POST['schoolid'], "int"));

Thanks in advance!

Robin
This topic has been closed for replies.

1 reply

Inspiring
March 1, 2007
before the update statement

$_POST['budget'] = str_replace(",",".",$_POST['budget']);

This will replace each comma with a dot in $_POST['budget'];

When you display, do the opposite

echo str_replace(".",",",$recordset_name['budget']);


--
Gareth
http://www.phploginsuite.co.uk/
PHP Login Suite V2 - 34 Server Behaviors to build a complete Login system.