user2685383
user2685383

Reputation: 1

Insert query not working in codeigniter

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

Upvotes: 0

Views: 7920

Answers (4)

CaPs LoCk
CaPs LoCk

Reputation: 150

Try Something Like this

$data = array(
   'user_id' => '$user_id' ,
   'photo_id' => '$photo_id' ,
   'album_id' => '$album_id'
);

$this->db->insert('photo_album', $data);

Upvotes: -1

Girish Kumar Sinha
Girish Kumar Sinha

Reputation: 832

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");

Upvotes: 1

Marc Steven Plotz
Marc Steven Plotz

Reputation: 543

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.

Upvotes: 0

Dipendra Gurung
Dipendra Gurung

Reputation: 5870

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);

Upvotes: 4

Related Questions