0

I am trying to run an insert query from codeigniter by using the following code

$this->db->query($query);

but I am getting the following error:

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 '' at line 4

INSERT INTO order_bank 
    (creation_date, order_type, so_no, 
    material_no, description, order_qty, no_of_panels, 
    division, job_number, customer_group, sales_office, 
    sales_group, project_name, project_manager, 
    net_value_myr, credit_status, so_delivery_date, 
    order_delivery_date) 
VALUES ( '2013-07-01', 'ZTOR', 3058627219, 
    101900000000, 'SUPPLY, MODIFY, INSTALL TEST VCU', 
    1, 0, 'AIS (TSM)', 'SC139203J01', 'Industry', 
    'SEA', 'DOM', 'MELAKA', 
    'Phua Tiang Hai', 42954.55, '', '2013-07-11', 
    '2013-07-05');

Filename: C:\wamp\www\system\database\DB_driver.php
Line Number: 330

But when I am running the above query in phpmyadmin its working perfectly. Please help me in sorting out the issue

6
  • single quote on '42954.55'. Actually, it's doesn't need. But, you need to test it. Commented Aug 15, 2013 at 9:28
  • check your $query variable again or show it over here. It possibly "" problem Commented Aug 15, 2013 at 9:30
  • but why can't you use codeigniter insert with array or object like this , $this->db->insert('order_bank', $data); Commented Aug 15, 2013 at 9:33
  • You can use $this->db->last_query(); to see what sql actually is codeigniter executing. Commented Aug 15, 2013 at 10:00
  • Show us the code you are using to build the $query variable Commented Aug 15, 2013 at 10:27

3 Answers 3

4

Use active records provided by Codeigniter, that would be much more safer and simpler!

http://ellislab.com/codeigniter/user-guide/database/active_record.html

Example:-

$this->db->set('description', $description);
$this->db->set('order_qty', $order_qty);
$this->db->set('no_of_panels', $no_of_panels);
$this->db->set('division', $division);
$this->db->set('job_number', $job_number);
$this->db->set('customer_group', $customer_group);
$this->db->set('sales_office', $sales_office);
$this->db->set('sales_group', $sales_group);
$this->db->set('project_name', $project_name);
$this->db->set('project_manager', $project_manager);
$this->db->set('net_value_myr', $net_value_myr);
$this->db->set('credit_status', $credit_status);
$this->db->set('so_delivery_date', $so_delivery_date);
$this->db->set('order_delivery_date', $order_delivery_date);
$this->db->insert('order_bank');

or if your data are stored in an array then you can do it simply running

$this->db->insert('order_bank', $data);
Sign up to request clarification or add additional context in comments.

Comments

1

you have to load database library in your controller class or autoload file.

In autoload file:

$autoload['libraries'] = array('database');

or in controller class:

$this->load->library("database");

Comments

0

42954.55 must be '42954.55'. Ignoring active record example because this has nothing to do with the question, which is why this query is failing.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.