I'm having a little code, where the user can select a number with or without decimal places. I added the step
attribute to my input type="number"
, So the user can insert decimals, as shown:
<form method="post" >
<input type='number' name='price' min='1' max='30' step=".01" required>
<input type='submit' name='submit'>
</form>
if(isset($_POST['submit']))
{
try{
require("conecction.php");
$db->beginTransaction();
$ins = $db->prepare("INSERT INTO items (price) VALUES (?)");
$ins->bindParam(1,$_POST['price']);
$ins->execute();
}
catch(PDOException $ex)
{
$db->rollBack();
echo "<p style=color:red;> There was an connection error.<p>";
die($ex->getMessage());
}
}
and my SQL table has the following format:
CREATE TABLE `items` (
`ID` int(11) NOT NULL,
`price` decimal(6,2) NOT NULL,
)
This code is functional and inserts the data into the DB as expected to be, but only it is inserting the closest number to the decimal point, for example the user inserts 21.4 I get 21 in my DB.