用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2496|回复: 6
收起左侧

[HELP] 急!求助CI高手哦

[复制链接]
发表于 2010-10-21 10:23:59 | 显示全部楼层 |阅读模式
$this->tour_model->add($uploads_slt);
$insert_id =$this->db->insert_id();
为什么返回$insert_id 为0 ,,,哪里错了哦
 楼主| 发表于 2010-10-21 10:24:24 | 显示全部楼层
数据都入库了 奇怪啊
发表于 2010-10-21 10:35:23 | 显示全部楼层
贴代码看一下,代码没错不会返回0。
 楼主| 发表于 2010-10-21 10:40:18 | 显示全部楼层
控制器
PHP复制代码
function submit(){
                //获取参数值
                $from_row=$this->input->post('per_page')?$this->input->post('per_page'):"0";
                $tour_category=$this->input->post('sql_category')?$this->input->post('sql_category'):"";
                $tour_category2=$this->input->post('sql_category2')?$this->input->post('sql_category2'):"";
                $keyword=$this->input->post('sql_keyword')?$this->input->post('sql_keyword'):"";
                $id=$this->input->post('id')?$this->input->post('id'):"";
                $duplicate=$this->input->post('duplicate')?$this->input->post('duplicate'):"";
               
                //图片上传
                if($_FILES['upfile']){   
                        $this->load->library('upload_class',$_FILES['upfile']);
                        $this->upload_class->setRootdir("uploads/");
                        $this->upload_class->setDir(date("Ymd"));
                        $slt_name=$this->upload_class->saveFile();
                }
                $slt_old=$this->input->post('upfile_old');     
 
                if(!empty($slt_name)||!empty($slt_old)){
                        $uploads_slt=$slt_old[0];      
                        if(!empty($slt_name)){
                                $uploads_slt=$slt_name[0];     
                        }
                }else{
                        $uploads_slt="";       
                }
               
                if(empty($id)){    //增加
                        $this->tour_model->add($uploads_slt);
                        $tss=$this->db->insert_id();
                        echo $tss;exit;
                        $insert_id =$this->db->insert_id(); //就是这里
                        //print_r($insert_id);exit;
                        $tour_arr=$this->tour_model->get_one($insert_id);
                        $this->tour_model->add_price($insert_id);                      
                        //增加操作记录
                        $this->admin_log_model->add(12,$tour_arr['title']);
复制代码

        。。。。。。。。。。。。。。
 楼主| 发表于 2010-10-21 10:42:28 | 显示全部楼层
MODEL
PHP复制代码
function add($upfile){
                $rn="\n";
                $kg=" ";
                $br="<br />";
                $str="";
                $string="";
 
                $baohan=str_replace('\\','',$_POST['baohan']);
                $baohan=str_replace($br,$str,$baohan);
                $baohan=str_replace($rn,$br,$baohan);  
               
                $buhan=str_replace('\\','',$_POST['buhan']);
                $buhan=str_replace($br,$str,$buhan);
                $buhan=str_replace($rn,$br,$buhan);            
               
                $biaozhun=str_replace('\\','',$_POST['biaozhun']);
                $biaozhun=str_replace($br,$str,$biaozhun);
                $biaozhun=str_replace($rn,$br,$biaozhun);                              
       
                $xuzhi=str_replace('\\','',$_POST['xuzhi']);
                $xuzhi=str_replace($br,$str,$xuzhi);
                $xuzhi=str_replace($rn,$br,$xuzhi);            
               
                $ts=str_replace('\\','',$_POST['ts']);
                $ts=str_replace($br,$str,$ts);
                $ts=str_replace($rn,$br,$ts);
               
                $tour_category2="";
                $num1=count($_POST['tour_category2']);
                for($i=0;$i<$num1;$i++){
                        if($_POST['tour_category2'][$i]!=""){
                                if($tour_category2==""){
                                        $tour_category2.=$_POST['tour_category2'][$i];         
                                }else{
                                        $tour_category2.="-".$_POST['tour_category2'][$i];
                                }
                        }
                }
               
                $ts_category="";
                $num2=count($_POST['ts_category']);
                for($j=0;$j<$num2;$j++){
                        if($_POST['ts_category'][$j]!=""){
                                if($ts_category==""){
                                        $ts_category.=$_POST['ts_category'][$j];               
                                }else{
                                        $ts_category.="-".$_POST['ts_category'][$j];   
                                }
                        }
                }
               
                $px = $_POST['px']?$_POST['px']:'1';
                $hidden = empty($_POST['hidden'])?0:$_POST['hidden'];
                $tuijian = empty($_POST['tuijian'])?0:$_POST['tuijian'];
                $qinzi = empty($_POST['qinzi'])?0:$_POST['qinzi'];
                $tejia = empty($_POST['tejia'])?0:$_POST['tejia'];
                $remai = empty($_POST['remai'])?0:$_POST['remai'];
                $zhifei = empty($_POST['zhifei'])?0:$_POST['zhifei'];
                $content = empty($_POST['content'])?'':$_POST['content'];
                $code = empty($_POST['code'])?'':$_POST['code'];
                $data = array(
                        'title'=>$_POST['title'],
                        'tour_category'=>$_POST['tour_category'],
                        'tour_category2'=>$tour_category2,
                        'ts_category'=>$ts_category,
                        'code'=>$code,
                        'days'=>$_POST['days'],
                        'tel'=>$_POST['tel'],
                        'departure_date'=>$_POST['departure_date'],
                        'reference_price'=> $_POST['reference_price'],
                        'tuijian'=> $tuijian,
                        'qinzi'=> $qinzi,
                        'tejia'=> $tejia,
                        'remai'=> $remai,
                        'zhifei'=> $zhifei,
                        'hidden'=>$hidden,
                        'px'=>$px,
                        'upfile'=>$upfile,
                        'content'=> $content,
                        'xc'=>$_POST['xc'],
                        'ts'=> $ts,
                        'baohan'=> $baohan,
                        'buhan'=> $buhan,
                        'biaozhun'=> $biaozhun,
                        'xuzhi'=> $xuzhi,
                        'addtime'=>date("Y-m-d"),
                        'modifytime'=>date("Y-m-d")
                );
                $this->db->insert('tour',$data);
                $id = $this->db->insert_id();
                $this->get_code($id,$code);
                if($_POST['xc']==2){
                        $total=count($_POST['daytitle']);
                        $data_xc = array();
                        for($i=0;$i<$total;$i++){
                                unset($data_xc);
                                if($_POST['daytitle'][$i]!=""){
                                        $data_xc["daytitle"]=$_POST['daytitle'][$i];
                                        $data_xc["daycontent"]=str_replace('\\','',$_POST['daycontent'][$i]);
                                        $data_xc["daycontent"]=str_replace($br,$str,$data_xc["daycontent"]);
                                        $data_xc["daycontent"]=str_replace($rn,$br,$data_xc["daycontent"]);
                                        $data_xc["breakfast"]=$_POST['breakfast'][$i];
                                        $data_xc["lunch"]=$_POST['lunch'][$i];
                                        $data_xc["supper"]=$_POST['supper'][$i];
                                        $data_xc["zs"]=$_POST['zs'][$i];
                                        $data_xc["jt"]=$_POST['jt'][$i];
                                        $data_xc["tour_id"]=$id;
                                }
                               
                                $this->db->insert('foolishtour',$data_xc);
                        }
                }      
                return $id;
        }
复制代码
发表于 2010-10-21 10:57:52 | 显示全部楼层
$this->db->insert('tour',$data);
$this->db->insert('foolishtour',$data_xc);

你这里有很多 insert 啊,建议你在 insert 以后马上取 id,否则就可能出问题。
 楼主| 发表于 2010-10-21 11:27:49 | 显示全部楼层
好 我试试 谢谢

本版积分规则