0

I try to insert data using codeigniter. But when my data have a question symbol, I get some error. I try direct into database its work properly but when I try run in codeigniter it's not working.

Can anyone help me, or any idea for solve this problem.

My query:

INSERT INTO WIK_POLICY (PRODUCT,ADV) VALUES ('CUP' ,'are you familiar with cup?')
5
  • INSERT INTO WIK_POLICY (PRODUCT,ADV) VALUES ('CUP' ,'are you familiar with cup?') that's is My query. Commented Jun 19, 2014 at 4:38
  • What error did codeigniter throw? Commented Jun 19, 2014 at 4:39
  • show your code ?????? Commented Jun 19, 2014 at 4:44
  • Need to know the Codeigniter script that produces the error Commented Jun 19, 2014 at 4:44
  • show your db insertion code and error you encountered.. Commented Jun 19, 2014 at 4:45

2 Answers 2

1

Use Codeigniter Standard instead of simple query,

$data = array(
       'title' => 'My title' ,
       'name' => 'My Name' ,
       'date' => 'My date'
    );

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

    // Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')

Reference :

CodeIgniter Insert Query

If you want to use simple method then,

$query = $this->db->query("YOUR QUERY");
Sign up to request clarification or add additional context in comments.

Comments

0

You have many ways to insert data in your database. Ill show the bests ways to do it.

Using set and insert function:

$this->db->set('name', $name);
$this->db->insert('mytable');

//RESULT : Produces: INSERT INTO mytable (name) VALUES ('{$name}');

Using $this->db->insert():

$data = array(
   'title' => 'My title' ,
   'name' => 'My Name' ,
   'date' => 'My date'
);

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

// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')

Try check if the structure of ADV field in mysql, check if is varchar or text and your limit of Characters.

I recommend you to use this function: $this->output->enable_profiler(TRUE);

The Profiler Class will display benchmark results, queries you have run, and $_POST data at the bottom of your pages. This information can be useful during development in order to help with debugging and optimization.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.