duanraotun1674 2013-03-28 09:06 采纳率: 100%
浏览 52

too long

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?

  • 写回答

1条回答 默认 最新

  • drhgzx4727 2013-03-31 05:57
    关注

    I'm pretty sure changing line 1 from this:

    $sid = $user->sid;
    

    to this:

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

    should do the trick...

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大