2015-12-07 56 views
-4

一直有一些问题,与此代码,由于某种原因,它可以在一个PHP脚本,但是这一次拒绝工作,我不知道,为什么,因为我敢新的PHP和学习POST和其他的东西,这是工作正常,但我不明白是什么问题,因为PDO是每个其他PHP文件相同,他们工作正常。语法错误,意外“:”在线56

我已经得到的错误:

语法错误,意外 ':' 上线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; 
+1

你刚刚在这个语句中错过了'单引号'$ res2-> bindParam(':catids,$ catoid,PDO :: PARAM_INT);' –

+1

你在这一行中缺少一个结束单引号(''') :'$ res2-> bindParam(':catids,$ catoid,PDO :: PARAM_INT);'*编辑:*该死,太迟:) – Hexaholic

+0

你为什么修复你的问题中的代码?它是否解决了实际问题? –

回答

-1

尝试将您的查询变更为:

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

从这一行(行情变化)

+0

这不会有什么区别。 –

-1

删除分号;)

编辑代码:

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

请说出downvote的原因 –

+0

这不是提问者询问错误的原因。此外,终止这样的查询,虽然不是必要的,但不会导致问题。 –

+0

不,这是因为这仅仅是@ SverriM.Olsen的错误。我相当确定。 –

0

看来你有概率LEM符合$insert->bindParam(':catid', $catoid, PDO::PARAM_INT);

尽量评论这条线,看看你的问题转移到下一个。

如果是这样,我认为它应该意味着有你的ORM和表结构的问题。

如果错误消失,再次检查你的数据库结构发生了什么变化。在wcf_forums表中可能有一些东西连接到整个表结构的catid字段。同时检查你的ORM配置表。

不知道,这将有助于解决您的问题,但是这就是我对你的地方做。