我目前有一个表单,其中提交了值以将数据添加到我的表中。我有一个字段“property_id
”,它是ENUM
。每次我尝试提交字段时,都会收到错误消息:
Fatal error: Uncaught mysqli_sql_exception: Data truncated for column 'property_id' at row 1 in ...
有什么办法可以通过我的表单向ENUM
字段添加数据吗?下面是我的代码,它将表单连接到数据库:
ini_set('display_errors', 1);
ini_set('log_errors', 1);
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$property_id = filter_input(INPUT_POST, 'property_id');
$firstline_address = filter_input(INPUT_POST, 'firstline_address');
$postcode = filter_input(INPUT_POST, 'postcode');
$vacant = filter_input(INPUT_POST, 'vacant');
if (!empty($property_id)) {
if (!empty($postcode)) {
$host = "";
$dbusername = "";
$dbpassword = "";
$dbname = "";
//new connection
$conn = new mysqli($host, $dbusername, $dbpassword, $dbname);
if (mysqli_connect_error()) {
die('Connect Error (' . mysqli_connect_errno() . ')'
. mysqli_connect_error());
} else {
$sql = "INSERT INTO property (property_id, firstline_address, postcode, vacant)
values ('$property_id', '$firstline_address', '$postcode', '$vacant')";
if ($conn->query($sql)) {
echo "New property has been successfully added. Refresh page to view new property in the table below.";
} else {
echo "Error: ";
//. $sql ."<br>".$conn->error;
}
$conn->close();
}
} else {
echo "All fields are required!";
die();
}
} else {
echo "Please fill out all fields to continue.";
die();
}