Codeigniter request does not insert

Data is sent from the front end as follows:

var data = {
                'user_id':userid,
                'qid':array[qnum].qid,
                'user_ans':userAnswers[qnum].answer,
                'user_time':userTime,
                'exerciseid':exid,
                'point_scored':points
        };
$.post('<?php echo base_url()?>main/update_user_score',
            { myData : data },
            function(result){} );

And in my "main" controller I have:

$post_data = $_POST['myData'];

$data = array(
            'user_id' => $post_data[user_id] ,
            'qid' => $post_data[qid],
            'user_ans' => $post_data[user_ans],
            'user_time' => $post_data[user_time],
            'exerciseid' => $post_data[exerciseid],
            'point_scored' => $post_data[point_scored]
        );

$this->load->model('Question_model','questions');
$this->questions->update_user_attempt($data);

In my Question_model / update_user_attempt:

error_log("data in model BEFORE INSERT:" . json_encode($data));
$this->db->insert('user_attempt', $data);
error_log("data in model AFTER INSERT: ");

The problem is that the data reaches (at least, it seems to me) to such an extent. Here's the log entry:

[23-Apr-2012 16:04:47] data in model BEFORE INSERT:{"user_id":"5","qid":"3","user_ans":"d","user_time":"3","exerciseid":"cr1","point_scored":"35"}

BUT there is no record "after insertion". The insertion itself does not occur, and logging after insertion is not performed.

I read perfectly from the DB. So I checked in phpmyadmin the user privileges of the user in "config / database.php", and this user has ALL privileges, including INSERT.

So, two questions:

  • What is the problem? What mistake am I making?
  • How do I even start figuring out what happens with the insert? (I can't find anything in magazines.)
  • xampp/apache/logs/error.log xampp/php/logs/php_error_log. ?
+3
5

$this- > db → _ error_message(); db

...

error_log("data in model BEFORE INSERT:" . json_encode($data));
$this->db->insert('user_attempt', $data);
echo $this->db->_error_message();
error_log("data in model AFTER INSERT: ");
+3

$this->db->last_query() insert, , insert. SQL-, , .

+1

ini_set("display_errors", "1");

var_dump($data); die(); 

, . , , .

+1

$post_data['user_id']

+1
  • , : json_decode json_encode?

  • error_reporting(E_ALL);?

0
source

All Articles