I imagine this is a simple issue, I simply cannot find out where or why. (hope this isn't a duplicate)..
My intent is to grab the info from an input and from a textarea and insert it into my database into the proper table that already exists "journals". However after hitting submit and without receiving any errors there is nothing added to the database... thoughts?
here is my "view" (post.php):
<fieldset>
<form method="post" action="push.php">
<input type="text" name="datetitle" /><br />
<textarea name="journalcontent"></textarea><br />
<input type="submit" />
</form>
<?php echo $datetitle ?>
<p><?php $output ?></p>
</fieldset>
here is my "index" (push.php) with obvious parts omitted:
<?php
$dsn = '*';
$username = '*';
$password = '*';
include "model.php";
try {
$db = new PDO($dsn, $username, $password);
} catch (PDOException $exc) {
echo 'connection failed';
exit;
}
echo 'goodzo';
$datetitle = $_POST['datetitle'];
$journalcontent = $_POST['journalcontent'];
if (!empty($datetitle)) {
$output = add_entry($datetitle, $journalcontent);
} else {
$output = "empty";
}
include "post.php";
?>
and lastly my model.php:
<?php
function add_entry($datetitle, $journalcontent) {
global $db;
$query = 'INSERT INTO journals
(entry_date, contents)
VALUES
($datetitle, $journalcontent)';
try {
$statement = $db->prepare($query);
$statement->execute();
$statement->closeCursor();
} catch (PDOException $e) {
$error_message = $e->getMessage();
display_db_error($error_message);
}
}
?>