插入表单;t插入表格?使用codeigniter框架


insert into form doesn't insert into table ? with codeigniter framework

数据库详细信息:

dbtable:来宾数据库列:id(A_I)、guestname、guestemail

当我提交数据时,它只是刷新页面,不采取任何行动。我是初学者,请告诉我问题出在哪里,为什么是

我用基本的php制作了插入表单,我通过了,但用codeigniter可能我还没有完全理解,看起来我的经验大约是1%或5%:D:D

控制器/访客.php:

<?php
class Guests extends CI_Controller {

   public function index($page = 'guests')
        {
        if ( ! file_exists(APPPATH.'/views/main/'.$page.'.php'))
        {
                // Whoops, we don't have a page for that!
                show_404();
        }
        $data['title'] = ucfirst($page);
        $data['pagedesc'] = 'Guests List';
        $this->load->view('include/header', $data);
        $this->load->model('guests_model');
        $data['records'] = $this->guests_model->getAll();
        $this->load->view('main/guests', $data);
        $this->load->view('include/footer', $data);
        }
   public function addnewguest($page = 'Add New Guest')
        {
        if ( ! file_exists(APPPATH.'/views/main/addnewguest.php'))
        {
                // Whoops, we don't have a page for that!
                show_404();
        }
        $data['title'] = ucfirst($page);
        $data['pagedesc'] = 'Please Fill Informations Below';
        $this->load->view('include/header', $data);                                 // loaded the header
        $this->load->model('guests_model');                                         // loaded the model 
        $this->load->view('main/addnewguest', $data);                               // loaded add new form
        if($this->input->post('createnew')) {                                             // if click add send information to addnewguestpost() function in the guest_model file
            $this->guests_model->addnewguestfunc();
        }
        $this->load->view('include/footer', $data);                                 // loaded the footer
        }
}

views/main/addnewguest.php

<form class="form-horizontal" action="<?php echo site_url('guests/addnewguest'); ?>" method="post">
  <div class="form-group">
    <label for="guestname" class="col-sm-2 control-label">Guest Name</label>
    <div class="col-sm-3">
      <input type="text" name="guestname" class="form-control" id="guestname" placeholder="Guest Name ...">
    </div>
  </div>
  <div class="form-group">
    <label for="guestemail" class="col-sm-2 control-label">Guest Email</label>
    <div class="col-sm-3">
      <input type="text" name="guestemail" class="form-control" id="guestemail" placeholder="Guest Email ..">
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
        <button type="submit" class="btn btn-default" name="createnew">Add</button>
    </div>
  </div>
</form>

models/guets_model.php

<?php
class Guests_model extends CI_Model {

    public function getAll() {
        $query = $this->db->get('guests');

        if($query->num_rows() > 0){
            return $query->result(); 
        } else {
            return FALSE;
        }
    }
    public function addnewguestfunc() {
        $data = array(
                'guestname' => $this->input->post('guestname'),
                'guestemail' => $this->input->post('guestemail')
        );


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

已解决

忘记了更改输入按钮,因为我从bootstrap基本模板中复制了它来练习。。

views/main/addnewguest.php更改按钮后输入:

<form class="form-horizontal" action="<?php echo site_url('guests/addnewguest'); ?>" method="post">
  <div class="form-group">
    <label for="guestname" class="col-sm-2 control-label">Guest Name</label>
    <div class="col-sm-3">
      <input type="text" name="guestname" class="form-control" id="guestname" placeholder="Guest Name ...">
    </div>
  </div>
  <div class="form-group">
    <label for="guestemail" class="col-sm-2 control-label">Guest Email</label>
    <div class="col-sm-3">
      <input type="text" name="guestemail" class="form-control" id="guestemail" placeholder="Guest Email ..">
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
        <input type="submit" class="btn btn-default" name="createnew">Add</input>
    </div>
  </div>
</form>