PHP代码点火器数据库错误

mhe*_*ers 0 php codeigniter

无法弄清楚这里有什么问题:

class Model_form extends CI_Model
{
  function __construct()
  {
        // Call the Model constructor
        parent::__construct();
  }

  function add_tree()
  {
    $v_treename = $this->input->post('f_treename');
    $v_treedesc = $this->input->post('f_treedesc');
    $v_treeid = $v_treename;
    $this->db->query("INSERT INTO trees (index, tree_name, tree_desc, tree_id) VALUES (NULL, '$v_treename', '$v_treedesc', '$v_treeid') "); //PROBLEM OCCURS HERE
} 
Run Code Online (Sandbox Code Playgroud)

得到此错误:

A Database Error Occurred
Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'index, tree_name, tree_desc, tree_id) VALUES (NULL, 'TEST', 'TEST', 'TEST')' at line 1 

我在另一个项目中使用了类似的代码,它工作得很好.使用MAMP在本地服务器上运行.感谢您的任何帮助,您可以提供.

cOl*_*le2 5

索引是mysql中的保留字.你需要在列名称周围添加反引号,即`index`,`tree_name`等.