dsh8009271 2015-05-23 17:24
浏览 40

如何在使用codeigniter刷新页面时停止插入数据

i need to stop insert data when refresh page iam new in codeigniter and can't do redirect easly,please support view:pages/home.php view which has a form

<html>
<head></head>
</body>
<?php echo validation_errors(); ?>
<?php echo form_open('speed/insert_to_db'); ?>

Branch: <input type="text" name="branch" /><br/>
Business Unit: <input type="text" name="buinessUnit" /><br/>
Device Type: <input type="text" name="deviceType" /><br/>
Brand: <input type="text" name="brand" /><br/>
Device Model: <input type="text" name="deviceModel" /><br/>
SN: <input type="text" name="SN" /><br/>
status: <input type="text" name="status" /><br/>
department: <input type="text" name="department" /><br/>
username: <input type="text" name="username" /><br/>
notes: <input type="textarea" name="notes" /><br/>
computername: <input type="text" name="computerName" /><br/>
Save:<input type="submit" name="save" />

</form>
</body>
</html>

model:add_model model which has insert_to_db function

       public function insert_into_db(){
           $post=$this->input->post();
           if(!isset($post['save'])) return;
           $data=array('Branch'=>$post['branch'],'BusinessUnit'=>$post['buinessUnit'],'DeviceType'=>$post['deviceType'],'Brand'=>$post['brand'],'DeviceModel'=>$post['deviceModel'],'SN'=>$post['SN'],'Status'=>$post['status'],'Departmant'=>$post['department'],'UserName'=>$post['username'],'Notes'=>$post['notes'],'ComputerName'=>$post['computerName']);
           $this->db->insert('hardware_assets', $data);
return $this->db->insert_id(); // if using mysql
       }
}

controller:

<?php

class Speed extends CI_Controller {

        function insert_to_db()
           {

             $this->load->model('add_model');

             $this->add_model->insert_into_db();
             $this->load->view('pages/home');//loading success view

           }


}
  • 写回答

2条回答 默认 最新

  • drvntaomy06331839 2015-05-23 17:35
    关注

    use $this->input->post('input_name') instead of raw code & check form submission in controller. i.e

    <?php
    
    class Speed extends CI_Controller {
    
        function insert_to_db()
           {
    
             $this->load->model('add_model');
             if($this->input->post('save')){
                $this->add_model->insert_into_db();
                $this->load->view('pages/home');//loading success view
             }
    
    
           }
    }
    

    also remove if(!isset($post['save'])) return; from model

    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)