迁移表单插入内容以使用pdo

时间:2019-04-07 15:26:51

标签: php mysqli pdo

我想迁移此代码以使用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);
?>

到目前为止,官方文件和卡路里示例对我来说没有任何意义

0 个答案:

没有答案