我正在尝试获取表省的id以将其作为外键插入表城市但是我的代码中存在问题,我无法将其作为FK插入城市表中。这是代码。
<?php
include 'connection.php';
$result=mysqli_query ($conn,"set character_set_results='utf8'");
$province_name=$_POST["province_name"];
$city_name = $_POST["city_name"];
$street = $_POST["street"];
//$id=$_POST["id"];
$result = mysqli_query($conn,"INSERT INTO province (province_name) VALUES ('$province_name')");
$id=$_POST["province_id"];
$id= mysql_insert_id($conn);
mysql_free_result( $result );
$result = mysqli_query($conn,"INSERT INTO city (pidfk,city_name, street) VALUES ('$id','$city_name','$street')");
$res=array();
//$res['check']=false;
if(mysqli_multi_query($conn,$result))
{
$res['check']=true;
}
header('Content-Type: application/json');
echo json_encode($res);
?>
答案 0 :(得分:0)
您在使用mysql_insert_id
时正在使用mysqli
。你不能同时使用
将mysql_insert_id
更改为mysqli_insert_id