虽然数据库功能正常但数据没有插入数据库

时间:2016-01-21 14:10:27

标签: php mysql codeigniter

虽然我的数据库连接工作正常,但即使每次按下提交按钮时都没有显示单个错误,并且在数据库中创建了新行,但是代替用户名和密码,它接收到值0。

login_con.php

    <?php
    if ( ! defined('BASEPATH')) exit('No direct script access allowed');

    class Login_con extends CI_Controller {

        /**
         * Index Page for this controller.
         *
         * Maps to the following URL
         *      http://example.com/index.php/welcome
         *  - or -  
         *      http://example.com/index.php/welcome/index
         *  - or -
         * Since this controller is set as the default controller in 
         * config/routes.php, it's displayed at http://example.com/
         *
         * So any other public methods not prefixed with an underscore will
         * map to /index.php/welcome/<method_name>
         * @see http://codeigniter.com/user_guide/general/urls.html
         */
        public function index()
        {
            //$this->load->model("New_model");
            $this->load->view("Login_view");
        }
        public function process()
        {
            //echo $this->input->post('user');
            $this->form_validation->set_rules("user","kamal","min_length[4]|max_length[10]|required");
            $this->form_validation->set_rules("userpass","kamal123","min_length[4]|max_length[10]|required");

            if($this->form_validation->run() == FALSE)
            {
                $val_error=array(
                    "error"=> validation_errors()
                    );
                $this->session->set_flashdata($val_error);
                redirect("Login_con");
            }
            else
            {
                $user=$this->input->post('user');
                $password=$this->input->post('userpass');
                //$this->Login_model->login_info($user, $password);

                $login_details = array(
                'user_name'=>$user,
                'user_password'=>$password,
                );

                $this->load->model("Login_model");
                $this->Login_model->insert_logindata($login_details);

            }
        }


    }

    ?>

Login_model.php

<?php
class Login_model extends CI_Model {


    public function insert_logindata($login_details)
    {
        $this->db->insert("login",$login_details);

    }


    /*public function login_info($user,$password)
    {
        $this->db->insert("user_name"=>$user,"$user_password"=>$password);
        $run = $this->db->get("login");

        if($run->num_rows == 1)
        {
            return $run->row(0)->user_id;
        }
        else{
            return FALSE;
        }

    }
    */
}
?>

Login_view.php

<html>
    <head>
        <title>Login pannel</title>
        <link rel="stylesheet" href="<?php echo base_url();?>assets/css/bootstrap.css">
        <script src="<?php echo base_url();?>assets/js/jquery.js"></script>
        <script src="<?php echo base_url();?>assets/js/bootstrap.js"></script>
    </head>

    <body>
        <p>This is Login pannel</p>

            <?php if($this->session->flashdata("error")){
                echo $this->session->flashdata("error");
            } ?>
            <?php
                $attributes=array( "class" => "form-horizontal","method"=>"post");
                $in_attributes=array(
                "class" => "form-control",
                "name" => "user",
                "placeholder" => "Enter your name"
                );
                $in_pass_attributes=array(
                    "class"=>"form-control",
                    "name"=>"userpass",
                    "placeholder"=>"Enter your password",
                    "type"=>"password"
                    );
                $in_btn_attributs=array(
                    "class"=>"btn btn-success",
                    "name"=>"get_form",
                    "type"=>"submit",
                    "value"=>"Submit"
                    );
            ?>
        <?php
             echo '<div class="container">';
             echo form_open("Login_con/process",$attributes);
                echo form_label('Username');
                echo form_input($in_attributes);
                echo form_label('Password');
                echo form_input($in_pass_attributes);
                echo form_input($in_btn_attributs);
             echo form_close(); 
             echo '</div>';
             ?>
    </body>
</html>

0 个答案:

没有答案