【问题标题】:syntax error, unexpected ':' on line 56语法错误,第 56 行出现意外的 ':'
【发布时间】:2016-03-11 21:35:05
【问题描述】:

这段代码遇到了一些问题,由于某种原因,它可以在一个 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;

【问题讨论】:

  • 你只是在这个声明中错过了single quote$res2-&gt;bindParam(':catids, $catoid, PDO::PARAM_INT);
  • 你在这一行缺少一个单引号('):$res2-&gt;bindParam(':catids, $catoid, PDO::PARAM_INT); 编辑:该死的,太晚了:)
  • 为什么要修复问题中的代码?它是否解决了您的实际问题?
  • 优化 - 您更改了 hardik 和 Hexaholic 指出的那一行 - 这解决了问题吗?
  • 嘿 - 是的,当我查看帖子中的代码时,我注意到了它,但是它并没有指向错误中的那一行,如果它是在发布之前就已经修复了,但感谢您的帮助! :)

标签: php syntax-error


【解决方案1】:

看来你在$insert-&gt;bindParam(':catid', $catoid, PDO::PARAM_INT);行有问题

尝试评论这一行,看看你的错误是否会转移到下一行。

如果是这样,我认为这应该意味着您的 ORM 和表结构存在问题。

如果错误消失,请再次检查您的数据库结构中发生了什么变化。整个表结构的 wcf_forums 表中的 catid 字段可能有一些连接。还要检查该表的 ORM 配置。

不确定它是否有助于解决您的问题,但这就是我会在您的位置上做的事情。

【讨论】:

    【解决方案2】:

    尝试将您的查询更改为:

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

    (引用已更改)

    【讨论】:

    • 这不会有任何区别。
    【解决方案3】:

    从该行中删除;)之前的分号

    $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)");
    

    【讨论】:

    • 这不是提问者所询问的错误的原因。此外,像这样终止查询虽然没有必要,但不会导致问题。
    • 不,这是因为这只是@SverriM.Olsen 出现的错误。我很确定。
    • 错了。他们得到的错误是 PHP 语法错误。它与 SQL 没有任何关系。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-24
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 2020-04-23
    相关资源
    最近更新 更多