2016-01-24 46 views
0

我想通過PhPMyadmin中的codeigniter框架保存表單數據。但它不起作用。它會自動重定向到我的表單頁面。數據未徹底保存phpmyadmin

這裏是我的看法(表單頁面的)代碼:

<!DOCTYPE html> 
<html lang="en"> 

<head> 

    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <meta name="description" content=""> 
    <meta name="author" content=""> 

    <title><?php echo $title;?></title> 

    <!-- Bootstrap Core CSS --> 
    <link href="<?php echo base_url();?>bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"> 

    <!-- MetisMenu CSS --> 
    <link href="<?php echo base_url();?>bower_components/metisMenu/dist/metisMenu.min.css" rel="stylesheet"> 

    <!-- Custom CSS --> 
    <link href="<?php echo base_url();?>dist/css/sb-admin-2.css" rel="stylesheet"> 

    <!-- Custom Fonts --> 
    <link href="<?php echo base_url();?>bower_components/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"> 

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> 
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// --> 
    <!--[if lt IE 9]> 
     <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> 
     <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script> 
    <![endif]--> 

</head> 

<body> 
    <div id="page-wrapper"> 
     <div class="row"> 
      <div class="col-lg-12"> 
       <h1 class="page-header">Forms</h1> 
      </div> 
      <!-- /.col-lg-12 --> 
     </div> 
     <!-- /.row --> 
     <div class="row"> 
      <div class="col-lg-12"> 
       <div class="panel panel-default"> 
        <div class="panel-heading"> 
         Basic Form Elements 
        </div> 
        <div class="panel-body"> 
         <div class="row"> 
          <div class="col-lg-6"> 
           <form action"<?php echo base_url();?>super_admin/save_category" method="post" > 
            <div> 

             <?php 
             $message=$this->session->userdata('message'); 
             if($message){ 
              echo $message; 
              $this->session->unset_userdata('message'); 
             } 
             ?> 

            </div> 
            <div class="form-group"> 
             <label>Text Input</label> 
             <input class="form-control" name="category_name"> 
             <p class="help-block">Example block-level help text here.</p> 
            </div> 

            <div class="form-group"> 
             <label>Text area</label> 
             <textarea class="form-control" name="category_description" rows="3"></textarea> 
            </div> 

            <div class="form-group"> 
             <label>Radio Buttons</label> 
             <div class="radio"> 
              <label> 
               <input type="radio" name="publication_status" id="optionsRadios1" value="1" checked>Published 
              </label> 
             </div> 
             <div class="radio"> 
              <label> 
               <input type="radio" name="publication_status" id="optionsRadios2" value="0">Unpublished 
              </label> 
             </div> 

            </div> 

            <button type="submit" class="btn btn-default">Submit </button> 
            <button type="reset" class="btn btn-default">Reset </button> 
           </form> 
          </div> 

         </div> 
         <!-- /.row (nested) --> 
        </div> 
        <!-- /.panel-body --> 
       </div> 
       <!-- /.panel --> 
      </div> 
      <!-- /.col-lg-12 --> 
     </div> 
     <!-- /.row --> 
    </div> 

</div> 
<!-- /#wrapper --> 

<!-- jQuery --> 
<script src="<?php echo base_url();?>bower_components/jquery/dist/jquery.min.js"></script> 

<!-- Bootstrap Core JavaScript --> 
<script src="<?php echo base_url();?>bower_components/bootstrap/dist/js/bootstrap.min.js"></script> 

<!-- Metis Menu Plugin JavaScript --> 
<script src="<?php echo base_url();?>bower_components/metisMenu/dist/metisMenu.min.js"></script> 

<!-- Custom Theme JavaScript --> 
<script src="<?php echo base_url();?>dist/js/sb-admin-2.js"></script> 

這裏是我的控制器代碼:

<?php 
//session_start(); 
defined('BASEPATH') OR exit('No direct script access allowed'); 
/** 
* 
*/ 
class Super_Admin extends CI_Controller 
{ 
    public function __construct(){ 
     parent::__construct(); 
     $admin_id=$this->session->userdata('admin_id'); 
     if($admin_id==NULL){ 
      redirect('admin_login','refresh'); 
     } 
    } 
    public function index() 
     { 

      $this->load->view('admin/admin_master'); 
     } 
     public function add_category(){ 
      $data=array(); 
      //$data['admin_content']=$this->load->view('admin/add_category','',TRUE); 
      $data['title']='Add category'; 
      $this->load->view('admin/add_category',$data); 
     } 
     public function save_category(){ 
      $data=array(); 
      $data['category_name']=$this->input->post('category_name',TRUE); 
      $data['category_description']=$this->input->post('category_description',TRUE); 
      $data['publication_status']=$this->input->post('publication_status',TRUE); 
      $this->super_admin_model->save_category_info($data); 
      $sdata=array(); 
      $sdata['message']="Save Category information successfully"; 
      $this->session->set_userdata($sdata); 
      redirect('super_admin/add_category'); 
     } 

    public function logout(){ 
     $this->session->unset_userdata('admin_name'); 
     $this->session->unset_userdata('admin_id'); 
     $sdata=array(); 
     $sdata['message']='You are successfully logout!'; 
     $this->session->set_userdata($sdata); 
     redirect('admin_login','refresh'); 
    } 
} 


?> 

這裏是我的模型代碼:

<?php 

class Super_Admin_Model extends CI_Model{ 
    public function save_category_info($data){ 
     $this->db->insert('tbl_category',$data); 

    } 
} 
?> 
+0

您的控制器應該只有第一個字母大寫的文件和類名。與您的模型一樣。 – user4419336

+0

我不明白你說了什麼。即使是模型,我也把所有班級名稱都寫成大寫字母。這沒有錯。 – Hola

回答

0

您忘記了加載模型。

public function save_category(){ 
      $this->load->model('super_Admin_Model', 'model'); //May be you forget this. 

      $data= array(
        'category_name' => $this->input->post('category_name',TRUE), 
        'category_description' => $this->input->post('category_description',TRUE), 
        'publication_status' => $this->input->post('publication_status',TRUE) 
        ); 

      $this->model->save_category_info($data); 

      $sdata=array(); 
      $sdata['message']="Save Category information successfully"; 
      $this->session->set_userdata($sdata); 
      redirect('super_admin/add_category'); 
     } 
+0

我把我的模型放在「autoload.php」中。 – Hola

+0

請檢查型號名稱的情況。我的意思是'super_Admin_Model'不是'super_admin_model'。 –