I want to create a php code that will insert value to to tables but i want table one "id" and table two "product_id" to be the same thing. this is my below code that insert values to the database but table one "id" do not correspond to table two "product_id"
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
$name = $_POST['name'];
$image = $_POST['image'];
$price = $_POST['price'];
$stock = $_POST['stock'];
$description = $_POST['description'];
$status = $_POST['status'];
require_once('dbConnect.php');
$sql ="SELECT id FROM product ORDER BY id ASC";
$res = mysqli_query($con,$sql);
$id = 0;
while($row = mysqli_fetch_array($res)){
$id = $row['id'];
}
$imagename = "$id.png";
$path = "uploads/$id.png";
$storage = "$id.png";
$actualpath = "http://localhost/markeet/$path";
$sql = "INSERT INTO product (name,image,price,stock,draft,description,status,created_at,last_update) VALUES ('$name','$storage','$price','$stock','0','$description','$status','','');";
$sql .= "INSERT INTO product_category (product_id, category_id)
VALUES ('', '$stock');";
if ($con->multi_query($sql) === TRUE) {
echo "New records created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
if(mysqli_query($con,$sql)){
file_put_contents($path,base64_decode($image));
echo "Successfully Uploaded";
}
mysqli_close($con);
}else{
echo "Error";
}