• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't submit to database

Hi - I'm trying to troubleshoot this code - I'm getting a database error for this statement:

class Model_form extends CI_Model
      function __construct()
            // Call the Model constructor

      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

This is the error I get:

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

Index is a keyword in mysql so try this. it may help you
$this->db->query("INSERT INTO trees (`index`, `tree_name`, `tree_desc`, `tree_id`) VALUES (NULL, '$v_treename', '$v_treedesc', '$v_treeid') "); //PROBLEM OCCURS HERE

Thanks! That was it.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.