I have a field in a MySQL database table called mileage
and its type is varchar(32)
On my webpage I have an input field where user can type in mileage and send the form
Here is some PHP validation for the mileage input:
if (empty($_POST["mileage"])) {
$mileageErr = "Mileage required";
}
else{
$mileage = htmlspecialchars($_POST["mileage"]);
}
When I insert the mileage into a db table:
// validation omitted...
$query = $db->prepare("INSERT INTO cars VALUES ($mileage)");
$result = $query->execute();
When I enter the number 0
into the input field and submit it, I get the error "Mileage required"
.
Why am I getting this error? I have set the type to be varchar(32), it should accept any string input up to length 32 right?
Or is there something I don't know about leading zero's?