我想迁移此代码以使用pdo
该表单具有一个自动完成字段nuts3,其他两个值是邮政编码和位置 根据nuts3的值,它还会插入nuts2和nuts1
<?php
require_once ("/includes/config.php");
$cp = $_POST['insert_cp'];
$localidad = $_POST['insert_localidad'];
$nuts3 = $_POST['nuts3'];
$insert = "INSERT INTO codigopostal (cp,localidad,fk_nuts3_id,fk_nuts2_id,fk_nuts1_id,fk_pais_id) VALUES ('$cp','$localidad',(SELECT nuts3_id FROM nuts3 WHERE nuts_3 = '$nuts3'),(SELECT fk_nuts2_id FROM nuts3 WHERE nuts_3 = '$nuts3'),(SELECT fk_nuts1_id FROM nuts3 WHERE nuts_3 = '$nuts3'),(SELECT fk_pais_id FROM nuts3 WHERE nuts_3 = '$nuts3'))";
if ($dbconn->query($insert) == TRUE){
$last_id=$dbconn->insert_id;
echo "ID CP:" . $last_id;
} else {
echo "Error: " . $insert . "<br>" . $conn->error;
}
mysqli_close($dbconn);
?>
到目前为止,官方文件和卡路里示例对我来说没有任何意义