Assuming you are doing this through PHP (based on you tagging it) and assuming that you need an insert into both tables, the basic jist would be (also assuming the id field in tasks is auto-increment):
$stmt1 = $conn->prepare("INSERT INTO tasks (fields, other_fields) VALUES (?, ?)"))
{
$stmt1->bind_param("ss",$fields, $other_fields);
$stmt1->execute();
$lastid = $conn->insert_id;
$stmt1->close();
}
Now you can use the variable $lastid as the value when you insert the samples data.
$stmt2 = $conn->prepare("INSERT INTO samples (id, other_fields, task_id) VALUES (?, ?, /)"))
{
$stmt2->bind_param("isi",$ID, $other_fields, $lastid);
$stmt2->execute();
$stmt2->close();
}
If samples already exists and you need to update it with the id from tasks, you'd just update samples after the insert into tasks, assuming you have something to use in the where clause that can uniquely identify the record you want updated :
$stmt2 = $conn->prepare("UPDATE samples set task_id = ? where user_id - ?)
$stmt2->bind_param("ii",$lastid, $user_id);
$stmt2->execute();
$stmt2->close();
}
else {
die(mysqli_error($conn));
}
I'm making a lot of assumptions, I know. But I can't comment yet so this is my only way of assisting.