i want save form data through codeigniter framework in phpmyadmin.but it's not working. redirected form page automatically.
here view (form page's) code :
<!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 , respond.js ie8 support of html5 elements , media queries --> <!-- warning: respond.js doesn't work if view 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 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>
and here controller code :
<?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 logout!'; $this->session->set_userdata($sdata); redirect('admin_login','refresh'); } } ?>
and here model code :
<?php class super_admin_model extends ci_model{ public function save_category_info($data){ $this->db->insert('tbl_category',$data); } } ?>
you forgot load model.
public function save_category(){ $this->load->model('super_admin_model', 'model'); //may 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'); }
Comments
Post a Comment