i have this code where i insert post details to mysql and another function to add photo details to mysql. how can i get the last insert id of the post to insert into the photos table as post_id
function add_img($whichimg,$title)
{
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$sql = "INSERT INTO photos (post_id,title, src) VALUES ('$this->$postid','$title','$whichimg')";
$add_to_db = $conn->query($sql) or die(mysqli_error());
return $add_to_db;
}
function add_post($subject,$content)
{
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$sql = "INSERT INTO posts (subject, content) VALUES ('$subject','$content')";
$add_to_db = $conn->query($sql) or die(mysqli_error());
$postid=$mysqli->insert_id;
}
add_post is called first.. add_img is called several times afterwards depending on the number of photos
Is there a way to call thi $id in this function onto another ?
SOLVED IT WITH $this->id;
$threadId = mysql_insert_id();add_img($whichimg, $title, $postId)