'1366 incorrect decimal value for column bikeprice at row 1
I use a sql insert statement that the values are coming from a form input based on active record design pattern and it throws me the above error, and I don’t know how to fix it. The sql insert statement is as follow:
$sql = “INSERT INTO bikes(bikename, bikeprice, bikeimage, description) VALUES ( ‘$this->bikename’,’$this->bikeprice’,’$this->bikeimage’,’$this->description’)”;
The main problem is with the bikeprice which the data type is decimal(9,2) in Php my admin database. $this->bikeprice is the class property which is defined in the
__construct($args=[]){ $this->bikeprice = $args[‘bikeprice’] ?? ‘’; ……}
and
if(isset($_POST[‘Insert’])){
$args = [];
$args[‘bikeprice’] = $_POST[‘bikeprice’] ?? NULL;
…
$bike = new Bike($args); …
}
I mean by this how to store a decimal value from an input field to database.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
