数据未添加到数据库

时间:2018-09-19 07:12:13

标签: database codeigniter

试图解决关于我的代码的问题。很长一段时间都没有编写代码点火器了。当我单击“添加项目按钮”时,它仅停留在同一页面上,没有任何反应。.这是我的视图和模型功能:

查看:

    <form action="<?php echo base_url().'item/addItem' ?> " method="post">

                    <div class="form-group">
                        <label>Name of Patient</label>
                        <input type="name" class="form-control" name="patient_name" placeholder="Name Here" value="<?php echo set_value('patient_name'); ?>">
                    </div>

                    <div class="form-group">
                        <label>Age</label>
                        <input type="input" class="form-control" name="age" placeholder="Age Here" value="<?php echo set_value('age'); ?>">
                    </div>

                    <div class="form-group">
                        <label>Date</label>
                        <input type="date" class="form-control" name="date" placeholder="Date" value="<?php echo set_value('date'); ?>">
                    </div>

                    <div class="form-group">
                        <label>Grade/PD</label>
                        <input type="input" class="form-control" name="grade" placeholder="Grade/PD Here" value="<?php echo set_value('grade'); ?>">
                    </div>

                    <div class="form-group">
                        <label>Frame No.</label>
                        <input type="input" class="form-control" name="frame_no" placeholder="Frame No. Here" value="<?php echo set_value('frame_no'); ?>">
                    </div>

                    <div class="form-group">
                        <label>Frame Amount</label>
                        <input type="input" class="form-control" name="frame_amo" placeholder="Frame Amount Here" value="<?php echo set_value('frame_amo'); ?>">
                    </div>

                    <div class="form-group">
                        <label>Lens Type/Amount</label>
                        <input type="input" class="form-control" name="lens_typeamo" placeholder="Lens Type/Amount Here" value="<?php echo set_value('lens_typeamo'); ?>">
                    </div>

                    <div class="form-group">
                        <label>Laboratory</label>
                        <input type="input" class="form-control" name="labo" placeholder="Laboratory Here" value="<?php echo set_value('labo'); ?>">
                    </div>

                    <div class="form-group">
                        <label>Total Amount</label>
                        <input type="input" class="form-control" name="total" placeholder="Total Amount Here" value="<?php echo set_value('total'); ?>">
                    </div>

                    <div class="form-group">
                        <label>Saleslady</label>
                        <input type="input" class="form-control" name="saleslady" placeholder="Saleslady Name Here" value="<?php echo set_value('saleslady'); ?>">
                    </div>

                    <div class="form-group">
                        <label>Doctor</label>
                        <input type="input" class="form-control" name="doctor" placeholder="Doctor Name Here" value="<?php echo set_value('doctor'); ?>">
                    </div>


                    <a href="<?php echo base_url().'item/itemlistadmin'?>" class="btn btn-info " role="button"><span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> BACK </a>
                    <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> ADD ITEM</button>
                </form>

我不确定在此区域输入的内容是否正确:C

型号:

    public function addItem(){

        $patient_name = $this->input->post('patient_name');
        $age = $this->input->post('age');
        $date = $this->input->post('date');
        $grade = $this->input->post('grade');
        $frame_no = $this->input->post('frame_no');
        $frame_amo = $this->input->post('frame_amo');
        $lens_typeamo = $this->input->post('lens_typeamo');
        $labo = $this->input->post('labo');
        $total = $this->input->post('total');                       
        $saleslady = $this->input->post('saleslady');
        $doctor = $this->input->post('doctor'); 


        $item = array(
            'px_name' => $patient_name,
            'px_age' => $age,
            'px_date' => $date,
            'px_grade' => $grade,
            'px_frame_no' => $frame_no,
            'px_frame_amo' => $frame_amo,
            'px_lens_typeamo' => $lens_typeamo,
            'px_labo' => $labo,
            'px_total' => $total,
            'px_saleslady' => $saleslady,
            'px_doctor' => $doctor
        );

    $this->db->insert('tblitem',$item);

}

这是我的数据库:

see here 不知道要更改什么了:'<请帮助。谢谢!

3 个答案:

答案 0 :(得分:0)

应该是

控制器:

public function addItem() {

    $patient_name = $this->input->post('patient_name');
    $age = $this->input->post('age');
    $date = $this->input->post('date');
    $grade = $this->input->post('grade');
    $frame_no = $this->input->post('frame_no');
    $frame_amo = $this->input->post('frame_amo');
    $lens_typeamo = $this->input->post('lens_typeamo');
    $labo = $this->input->post('labo');
    $total = $this->input->post('total');
    $saleslady = $this->input->post('saleslady');
    $doctor = $this->input->post('doctor');

    $item = array(
        'px_name' => $patient_name,
        'px_age' => $age,
        'px_date' => $date,
        'px_grade' => $grade,
        'px_frame_no' => $frame_no,
        'px_frame_amo' => $frame_amo,
        'px_lens_typeamo' => $lens_typeamo,
        'px_labo' => $labo,
        'px_total' => $total,
        'px_saleslady' => $saleslady,
        'px_doctor' => $doctor
    );

    $this->db->insert($item);
}

型号:

public function insert($item)
{
  $this->db->insert('tblitem', $data);
}

答案 1 :(得分:0)

尝试一下:

控制器

.width-very-large{
  width: calc(95vw * 1);
}
.width-large{
  width: calc(95vw * 0.75);
}
.width-normal{
  width: calc(95vw * 0.4);
}
.width-small{
  width: calc(95vw * 0.35);
}
//...
//and same with height

模型

    public function addItem()
    {
    $item=array(  
        'patient_name' = $this->input->post('patient_name'),
        'age' = $this->input->post('age'),
        'date' = $this->input->post('date'),
        'grade' = $this->input->post('grade'),
        'frame_no' = $this->input->post('frame_no'),
        'frame_amo' = $this->input->post('frame_amo'),
        'lens_typeamo' = $this->input->post('lens_typeamo'),
        'labo' = $this->input->post('labo'),
        'total' = $this->input->post('total'),
        'saleslady' = $this->input->post('saleslady'),
        'doctor' = $this->input->post('doctor'),     
        );
        $this->ModelName->addItem($item); 
    }

答案 2 :(得分:0)

控制器代码:
   公共功能add_item()

{

$ data = array(

'患者名称'= $ this-> input-> post('患者名称'),

'age'= $ this-> input-> post('age'),

'date'= $ this-> input-> post('date'),

'grade'= $ this-> input-> post('grade'),

'frame_no'= $ this-> input-> post('frame_no'),

'frame_amo'= $ this-> input-> post('frame_amo'),

'lens_typeamo'= $ this-> input-> post('lens_typeamo'),

'labo'= $ this-> input-> post('labo'),

'total'= $ this-> input-> post('total'),

'saleslady'= $ this-> input-> post('saleslady'),

'医生'= $ this-> input-> post('doctor'),

);

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

$ this-> model_name-> add_item($ data);

}

  model's code :

  public function add_item($data){

$ this-> db-> insert('table_name',$ data);

}

不要忘记检查.htaccess文件和base_url