解析错误:语法错误,bindValue中出现意外的T_VARIABLE

时间:2013-09-15 17:49:48

标签: php

if (isset($_SESSION['logged_in'])) {
if (isset($_POST['title'], $_POST['content'])) {
    $title = $_POST['title'];
    $content = $_POST['content'];

    if (empty($title) or empty($content)) {
        $error = 'All fields are required!';
    } else {
        $query = $pdo->prepare("INSERT INTO articles (atricle_title, atricle_text, atricle_timestamp) VALUES (?, ?, ?)")

        $query->bindValue(1, $title); //error is here
        $query->bindValue(2, $content);
        $query->bindValue(3, time());

        $query->execute();

        header(Location: index.php);
}

有人知道这里有什么问题吗? 代码本身就更多了,但这只是相关部分。

感谢。

4 个答案:

答案 0 :(得分:1)

$query = $pdo->prepare("INSERT INTO articles (atricle_title, atricle_text, atricle_timestamp) VALUES (?, ?, ?)")

在此行中,;缺失

这一行也是错误的:

header(Location: index.php);

它必须如下所示:

header("location: index.php");

答案 1 :(得分:1)

错过;在下面一行的末尾,这就是当你试图绑定值时它在下一行显示错误的原因。 $ query = $ pdo-> prepare(“INSERT INTO articles(atricle_title,atricle_text,atricle_timestamp)VALUES(?,?,?)”);

还有标题(Location:index.php);需要将参数作为字符串转换为头函数。

请尝试一下,如果有任何问题我也知道。

答案 2 :(得分:0)

发生错误是因为PHP假定包含查询的行尚未结束,然后下一个字符违反了语法规则。 将半冒号;添加到查询行。

$query = $pdo->prepare("INSERT INTO articles (atricle_title, atricle_text, atricle_timestamp) VALUES (?, ?, ?)");

答案 3 :(得分:0)

您错过了 ; 语句中的 PDO quotes > header()

<?php

if (isset($_SESSION['logged_in'])) {
if (isset($_POST['title'], $_POST['content'])) {
    $title = $_POST['title'];
    $content = $_POST['content'];

    if (empty($title) or empty($content)) {
        $error = 'All fields are required!';
    } else {
        $query = $pdo->prepare("INSERT INTO articles (atricle_title, atricle_text, atricle_timestamp) VALUES (?, ?, ?)");

        $query->bindValue(1, $title); //error is here
        $query->bindValue(2, $content);
        $query->bindValue(3, time());

        $query->execute();

        header("Location: index.php");
}