语法错误,意外':'在56号线上

时间:2015-12-07 10:06:01

标签: php syntax-error

这个代码遇到了一些问题,由于某种原因它可以在一个PHP脚本上工作,但是这个脚本拒绝工作,我不知道为什么,因为我对PHP很新,学习POST等这些工作正常,但我无法看到问题所在,因为PDO与其他所有PHP文件相同,而且工作正常。

我得到的错误:

  

语法错误,意料之外':' 第56行(又名:catid BindParam)

和我的代码:

<?PHP
if (!defined('init_executes'))
{   
    header('HTTP/1.0 404 not found');
    exit;
}

$CORE->loggedInOrReturn();

//prepare multi errors
$ERRORS->NewInstance('forums_forum_forum');
//bind on success
$ERRORS->onSuccess('Forum Sucessfully Created..', '/index.php?page=forums');

$name1 = (isset($_POST['name']) ? $_POST['name'] : false);
$desc1 = (isset($_POST['desc']) ? $_POST['desc'] : false);
$catoid = (isset($_POST['catid']) ? $_POST['catid'] : false);
$rrtct1 = (isset($_POST['rrtct']) ? $_POST['rrtct'] : false);

if (!$name)
{
    $ERRORS->Add("Please enter a Forum title.");
}

if(!$catid)
{
    $ERRORS->Add("Please enter a Destination Catagory");
}

$ERRORS->Check('/index.php?page=forums');

####################################################################
## The actual script begins here

    //Determine the Position within the Category
    $res2 = $DB->prepare("SELECT `position` FROM `wcf_categories` WHERE id =:catids  ORDER BY `position` DESC LIMIT 1");
    $res2->bindParam(':catids', $catoid, PDO::PARAM_INT);
    $res2->execute();

    if ($res2->rowCount() > 0)
    {
        $row2 = $res2->fetch();

        $position = $row2 + 1;

        unset($row2);

    }
    else
    {
        $position = 0;
    }
    unset($res2);

    $insert = $DB->prepare("INSERT INTO wcf_forums (category, name, description, position, required_rank_create_thread) VALUES (:catid, :name, :desc, :pos, :rank_thread);");
    $insert->bindParam(':catid', $catoid, PDO::PARAM_INT);
    $insert->bindParam(':name', $name1, PDO::PARAM_STR);
    $insert->bindParam(':desc', $desc1, PDO::PARAM_STR);
    $insert->bindParam(':pos', $position, PDO::PARAM_INT);
    $insert->bindParam(':rank_thread', $rrtct1, PDO::PARAM_INT);
    $insert->execute();

    if ($insert->rowCount() < 1)
    {
        $ERRORS->Add("The website failed to insert the forum record.");
    }
    else
    {
        unset($insert);
        $ERRORS->triggerSuccess();
    }
    unset($insert);

####################################################################

$ERRORS->Check('/index.php?page=forums');

exit;

3 个答案:

答案 0 :(得分:0)

似乎您在第$insert->bindParam(':catid', $catoid, PDO::PARAM_INT);

中遇到问题

尝试评论此行并查看您的错误是否会移至下一行。

如果确实如此,我认为它应该意味着您的ORM和表结构存在问题。

如果错误消失,请再次检查数据库结构中的更改。可能有一些东西连接到整个表结构的wcf_forums表中的catid字段。还要检查该表的ORM配置。

不确定它是否有助于解决您的问题,但这就是我在您所处的地方所做的事情。

答案 1 :(得分:-1)

尝试将您的查询更改为:

$insert = $DB->prepare('INSERT INTO wcf_forums (category, name, description, position, required_rank_create_thread) VALUES (:catid, :name, :desc, :pos, :rank_thread);');

(报价已更改)

答案 2 :(得分:-1)

;

之前从此行中删除分号)
$insert = $DB->prepare("INSERT INTO wcf_forums (category, name, description, position, required_rank_create_thread) 
VALUES (:catid, :name, :desc, :pos, :rank_thread);");
                                                 ^

已编辑的代码:

$insert = $DB->prepare("INSERT INTO wcf_forums (category, name, description, position, required_rank_create_thread) VALUES (:catid, :name, :desc, :pos, :rank_thread)");
相关问题