-2

I have a simple insert record to add an item to a recordset. The data field for price is set to decimal and when the price field is sent e.g. 9.50 it appears in the database as 9.00. Why?

Here's the code from the php insert statement

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO buying (`user`, items, price) VALUES (%s, %s, %s)",
                   GetSQLValueString($_POST['user'], "text"),
                   GetSQLValueString($_POST['items'], "int"),
                   GetSQLValueString($_POST['price'], "int"));
Rich
  • 512
  • 1
  • 6
  • 18

1 Answers1

5

From the manual:

The declaration syntax for a DECIMAL column is DECIMAL(M,D).

So, what did you specify for D? Sounds like perhaps 0.


Edit

I don't know what GetSQLValueString is, but you wrote GetSQLValueString($_POST['items'], "int") which seems to imply that you're creating an integer, no?

If it's this function, I think you clearly meant GetSQLValueString($_POST['items'], "double").

Community
  • 1
  • 1
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055