我已经设法为一个简单的表单连接到数据库,该表单将存储一些条目。它确实显示了一个条目已与表单一起提交,但是它不显示提交的信息。相反,它在我在表中创建的条目列中显示 NULL。我需要它来显示提交的内容。这是我的代码:
if($_SERVER['REQUEST_METHOD'] == 'POST'
&& $_POST['submit']=='Save Entry'
&& !empty($_POST['title'])
&& !empty($_POST['entry']))
{
// Include database credentials and connect to the database
include_once 'db.inc.php';
$db = new PDO(DB_INFO, DB_USER, DB_PASS);
// Save the entry into the database
$sql = "INSERT INTO entries (title, entry) VALUES (?, ?)";
$stmt = $db->prepare($sql);
$stmt->execute(array($title, $entry));
$stmt->closeCusor();
// Get the ID of the entry we just saved
$id_obj = $db->query("SELECT LAST_INSERT_ID");
$id = $id_obj->fetch();
$id_obj->closeCursor();
// Continue processing information
}
// If both conditions aren't met, sends the user back to the main page
else {
header('Location: ../amin.php');
exit;
}