Php 语法错误,意外';:';在线56
这段代码一直有一些问题,出于某种原因,它可以在一个PHP脚本上运行,但这一个拒绝工作,我不知道为什么,因为我对PHP和学习帖子以及其他东西非常陌生,这工作正常,但我看不出问题出在哪里,因为PDO与其他所有PHP文件一样,工作正常 我得到的错误是: 语法错误,第56行出现意外“:”(又名:catid BindParam) 我的代码是:Php 语法错误,意外';:';在线56,php,syntax-error,Php,Syntax Error,这段代码一直有一些问题,出于某种原因,它可以在一个PHP脚本上运行,但这一个拒绝工作,我不知道为什么,因为我对PHP和学习帖子以及其他东西非常陌生,这工作正常,但我看不出问题出在哪里,因为PDO与其他所有PHP文件一样,工作正常 我得到的错误是: 语法错误,第56行出现意外“:”(又名:catid BindParam) 我的代码是: <?PHP if (!defined('init_executes')) { header('HTTP/1.0 404 not found');
<?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;
尝试将查询更改为:
$insert=$DB->prepare('insert-INTO-wcf_论坛(类别、名称、描述、位置、所需排名_创建_线程)值(:catid、:name、:desc、:pos、:rank_线程);)代码>
(引号已更改)删除分号代码>从这一行开始,在之前)
编辑的代码:
$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)行有问题代码>
试着注释这一行,看看你的错误是否转移到下一行
如果是这样,我认为这应该意味着ORM和表结构存在问题
如果错误消失,请再次检查数据库结构中的更改。在整个表格结构的wcf_forums表格中,可能有一些东西连接到catid字段。还要检查该表的ORM配置
不确定它是否有助于解决您的问题,但这就是我在您的位置上所做的。您刚刚错过了此语句中的单引号
$res2->bindParam(':catids,$catoid,PDO::PARAM_INT)代码>此行缺少结束单引号(”
):$res2->bindParam(':catids,$catoid,PDO::PARAM_INT)代码>编辑:该死,太晚了:)你为什么要修改问题中的代码?它解决了你这方面的实际问题吗?优化-你改变了hardik&Hexaholic注意到的那一行-这解决了问题吗?嘿-是的,我一看帖子中的代码就注意到了,但是它没有指向错误上的那一行,如果是的话,它会在发布之前得到修复,但是谢谢你的帮助!)这不会有任何区别。这不是提问者所问错误的原因。此外,终止这样的查询虽然不是必需的,但不会导致问题。不,正是因为这样,才会出现错误@SverriM.Olsen。我很确定,错了。他们得到的错误是PHP语法错误。它与SQL无关。
$insert = $DB->prepare("INSERT INTO wcf_forums (category, name, description, position, required_rank_create_thread) VALUES (:catid, :name, :desc, :pos, :rank_thread)");