I'm trying to get last id which i inserted already in database through another php file and in current php file i can't get last id to use it.
This is my code.
<?php
include "connection.php.php";
$sucess = 105;
$fail = 107;
$planImage = $_POST['projects_plan_images'];
$planFilename = $_POST['projectsPlanImagesNames'];
$last_id = mysqli_insert_id($con);
$planLength = count($planFilename);
for($i = 0; $i < $planLength; $i++) {
$imageNow = time();
$new_imageFilename = $imageNow . "_" . $planFilename[$i];
$sql6 = "INSERT INTO projects_plans_images(project_id, plan_image, plan_name) VALUES ('$last_id','$new_imageFilename','$new_imageFilename')";
$result6 = mysqli_query($con, $sql6);
$binary=base64_decode($planImage[$i]);
$file = fopen('files/plans_images/' . $new_imageFilename, 'wb');
fwrite($file, $binary);
fclose($file);
}
$jsonResult = '{"state":';
if($result){
$jsonResult.= $sucess;
}else {
$jsonResult.= $fail;
}
$jsonResult .="}";
print_r($jsonResult);
?>