数据不保存在数据库中


data is not save in database

我在CakePHP工作。我想将发布的数据保存到我的数据库中。所以我在控制器中创建了如下所示的功能:

function add_news()
{
    $this->_checkSession();
    $this->layout = "admin_inner";
    if(!empty($this->params['form'])) 
    {   
        $tit = $this->params['form']['title'];
        $con = $this->params['form']['content'];
        $query = "insert into news(news_title,news_content) values('".$tit."','".$con."')";
        echo $query;
        $this->News->query($query);
    }
    Configure::write('debug', '2');
}

我打印查询并在数据库中执行,然后它工作正常。但在这里它不执行。我没有新闻模型。

注意:我在CakePHP 1.3.13工作

首先你需要知道如何在 cakephp 中插入数据....链接是:- http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html

然后你可以尝试这个代码在表中插入数据

if(!empty($this->params['form'])) 
{   
    $tit = $this->params['form']['title'];
    $con = $this->params['form']['content'];
    $data = array(
            "news_title"=>$tit,
            "news_content"=>$con
            );
    $this->News->save($data);       
}
function add_news()
{
    $this->_checkSession();
    $this->layout = "admin_inner";
    if(!empty($this->params['form'])) 
    {   
        $tit = $this->params['form']['title'];
        $con = $this->params['form']['content'];
        $data = array(
            "news_title"=>$tit,
            "news_content"=>$con
           );
     $this->News->save($data); 
   }
   Configure::write('debug', '2');

}