0

I have an insert process. My development is under Drupal6. So i used the following method to insert into database table.

$sid = $user->sid;
$data   = array(
            'nid'           =>  $parent_nid,
            'vid'           =>  $parent_vid,
            'uid'           =>  $user_id,
            'time_start'    =>  time(),
            'session_id'    =>  $sid
);

drupal_write_record('quiz_node_results', $data);

Here the problem is, it is not inserting the value $sid. It inserts the default value 0 always in that field. But other values are inserted correctly. But it has value. I checked with by putting print_r($data).

In database table, session_id field's datatype is varchar.

For quick fix, i wrote actual insert query and inserted into it. That query is below.

$sql    =   "INSERT INTO {quiz_node_results}(nid, vid, uid, time_start, session_id) VALUES(".$parent_nid.",".$parent_vid.",".$user_id.",".time().", '".$sid."')";
db_query($sql);

It is working fine and inserts the value correctly. But i don't want to insert in this way because it is vulnerable.

I want to know why the above one is not working. Can anyone suggest where i went wrong?

4

1 回答 1

0

我很确定从此更改第 1 行:

$sid = $user->sid;

对此:

$sid = isset($user->sid) ? $user->sid : session_id();

应该做的伎俩...

于 2013-03-31T05:57:57.390 回答