-1

I am trying to get the id of the table province to insert it in the table city as foreign key but there is problem in my code, i cant the id to insert it in the city table as FK. this is the code.

<?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);
 ?>

1 Answers1

0

You are using mysql_insert_id while you are using mysqli. You cant use both

change mysql_insert_id to mysqli_insert_id

B. Desai
  • 16,414
  • 5
  • 26
  • 47