这是$ _POST数组:
Array
(
[car_id] => ford_ka
[marca] => Teste
[modelo] => Teste
[preco] => 123
[descricao] => otimo carro teste123
[tanque] => 123
[motor] => 320cv bom blablabla
)
所以我将其传递给变量
$c_id = filter_var($_POST["car_id"], FILTER_SANITIZE_STRING);
$marca = filter_var($_POST["marca"], FILTER_SANITIZE_STRING);
$modelo = filter_var($_POST["modelo"], FILTER_SANITIZE_STRING);
$preco = filter_var($_POST["preco"], FILTER_SANITIZE_NUMBER_INT);
$desc = filter_var($_POST["descricao"], FILTER_SANITIZE_STRING);
$tanque = filter_var($_POST["tanque"], FILTER_SANITIZE_NUMBER_INT);
$motor = filter_var($_POST["motor"], FILTER_SANITIZE_STRING);
我创建我的连接
$mysqli = new mysqli($mysql_host, $mysql_username, $mysql_password,$mysql_database);
if ($mysqli->connect_error) {
die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}
然后我准备数据
$statement = $mysqli->prepare("INSERT INTO cars_data (car_id, marca, modelo, preco, descricao, tanque, motor) VALUES(?, ?, ?, ?, ?, ?, ?)");
将其绑定到标记
$statement->bind_param('sssisis', $c_id, $marca, $modelo, $preco, $desc, $tanque, $motor);
并执行它
if($statement->execute()){
print "Your car with the id " . $c_id . "has been included";
}else{
print $mysqli->error;
}
}
那么,我没有得到什么?
更新!!!
这是我从日志中得到的消息: “ PHP致命错误:未被捕获的错误:在C:\ MAMP \ htdocs \ process.php:43中以布尔值调用成员函数bind_param()堆栈跟踪:#0 {main}抛出在C:\ MAMP \ htdocs \ process中。第43行的php”