So I'm a little stuck with the following. I have two tables, projects and change.
Projects:
- id
- title
- description
- datecreated
Change:
- id
- title
- description
- projectid FOREIGN KEY
- datecreated
i can't figure out how to
insert into change (name, description, projectid) value (:name, :description, :projectid)
select id from project
where name = $name
important - the name and description in the insert are provided by php variables using a form.
important - must use PDO
Actual Code:
$sql = "INSERT INTO change (title, description, project_id) SELECT :title, :description, id FROM project WHERE title = :project_title";
$query = $db->prepare($sql);
$query->execute(array(":title" => $title, ":description" => $description, ":project_title" => $created));
This is what I did in the end but Barmar gets the point for help on this and another question.
$sql = "INSERT INTO `change` (`title`, `description`, `project_id`) SELECT :title, :description, id FROM project WHERE title = :project_title";
$query = $db->prepare($sql);
$query->execute(array(":title" => $title, ":description" => $description, ":project_title" => $created));