Currently I am trying to write a single function in my php script that adds a new page into my database and updates the navigation table at the same time. For some reason both queries are failing, and I'm not sure what else I should do. This is my add_content function call:
elseif ($react == "add_content") {
echo 'add content';
$title = $_POST['title'];
$content = $_POST['content'];
$page = $_POST['page'];
if (!empty($title) && !empty($content) && !empty($page)) {
addcontent($title, $content, $page);
} else {
echo 'not enough info';
}
and this is my function:
function addcontent($title, $content, $page) {
global $db;
$query1 = "INSERT INTO `content`(`title`, `content`) VALUES (:title, :content)";
$query2 = "INSERT INTO `navigation` ('page', 'content_id') SELECT :page, c.content_id FROM content c WHERE title=:page;";
try {
$stat = $db->prepare($query1);
$stmt = $db->prepare($query2);
$stat->bindParam(':title', $title);
$stat->bindParam(':content', $content);
$stat->bindParam(':page', $page);
$stat->execute($query1);
$stmt->execute($query2);
$result = "<strong>$title</strong> added<p>";
} catch (Exception $ex) {
$result = "$title deltetion failed";
}
}
I know the two queries work because I've already tested them with dummy information, it's just getting them to work inside of this function that's causing the problem.
I'm not sure if this is needed, but just in case, this is my table to add content:
<form method="POST" action="index.php">
<input type="hidden" name="react" value="add_content">
<input type="hidden" name="page|title" value="admin">
<div align="center"><center><p>ADD A New Page<br>
Title: <input type="text" name="title|page" size="20"><br>
Content: <input type="text" name="content" size="20"><br>
<input type="submit" value="Submit"></p></center></div>
</form>