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