0

我已经设法为一个简单的表单连接到数据库,该表单将存储一些条目。它确实显示了一个条目已与表单一起提交,但是它不显示提交的信息。相反,它在我在表中创建的条目列中显示 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;
}
4

2 回答 2

1

您还没有为任何地方设置$title$entry。你也有一个错字,你试图打电话给 call closeCursor()

于 2013-05-22T22:25:09.210 回答
1

可能 register_globals 已关闭(有充分理由自 PHP 5.3 起已弃用)。这意味着您必须从 $_POST 数组中读取$title和读取:$entry

$title = $_POST['title'];
$entry = $_POST['entry'];
于 2013-05-22T22:25:48.477 回答