Welcome Guest, Not a member yet? Register   Sign In
Database insertion problem
#1

[eluser]simonCI[/eluser]
Hi! I'm new to CI, I've got a db problem.

My site controller:
Code:
class Site extends CI_Controller{

public function index(){
  $this->home();
}
.
.
.

public function insertValues(){
  $this->load->model("get_db");
  $newRow = array("name" => "blahblahblah"
  );
  $this->get_db->insert("$newRow");
  echo "Insert done";
  }
}

db model:
Code:
class Get_db extends CI_Model{
function getAll(){
  $guery = $this->db->query("SELECT * FROM test");
  
  return $guery->result();
}
function insert($data){
  $this->db->insert("test", $data);
}

When calling the insertValues control I get this error:
Quote:A Database Error Occurred

Error Number: 1054

Unknown column 'Array' in 'field list'

INSERT INTO `test` (`Array`) VALUES ('')

Filename: F:\wamp\www\ci_intro\system\database\DB_driver.php

Line Number: 330

However a simple insertion like below works, which indicates there is no wrong with the database.
Code:
$guery = $this->db->query("INSERT INTO test (name) VALUES ('insertion nmame')");

What do you guys say?

Thanks/Simon

#2

[eluser]ojcarga[/eluser]
Probably you need to change this

$this->get_db->insert("$newRow");

to

$this->get_db->insert($newRow);

Try and tell us
#3

[eluser]simonCI[/eluser]
[quote author="ojcarga" date="1335085417"]Probably you need to change this

$this->get_db->insert("$newRow");

to

$this->get_db->insert($newRow);

Try and tell us[/quote]
oh, that was the error. shame on me...

Thank you ojcarga!
#4

[eluser]ojcarga[/eluser]
Your welcome!




Theme © iAndrew 2016 - Forum software by © MyBB