在数据库中插入用户ID - codeigniter + mysql

时间:2017-06-19 01:40:57

标签: php mysql codeigniter insert

我试图在数据库中插入相应的用户ID,但我不知道我的错误在哪里

表单视图:

<div class="container">
<div class="col-md-6 col-md-offset-3">
    <form  name="form_iniciar" action="" method="POST">
        <div class="form-group">
            <label for="usuario">Usuario</label>
            <input type="text" class="form-control" name="username" id="username" required>
        </div>
        <div class="form-group">
            <label for="contraseña">Contraseña</label>
            <input type="password" class="form-control" name="password" id="password" required >
        </div>
        <input type="submit" value="Entrar" class="btn btn-primary" name="submit_log"/>

        <a href="<?php echo base_url().'usuarioscon/registro' ?> " title="Deseo registrarme">Registrarse</a>
    </form>
</div>

登录控制器:

public function index(){
    if($this->session->userdata('LoginCliente')){
        redirect('profile');
    }
    if(isset($_POST['password'])){
        $this->load->model('cliente');
        if($this->cliente->loginemp($_POST['username'],$_POST['password'])){
            $this->session->set_userdata('Login',$_POST['username']);
            redirect('PanelIndex');
        }elseif(isset($_POST['password'])){
        $this->load->model('cliente');
        if($this->cliente->login($_POST['username'],$_POST['password'])){
            $this->session->set_userdata('LoginCliente',$_POST['username']);
            redirect('profile');
        }else{
            redirect('login');              
        }
    }

    }

    $this->load->view('inicio/loginview');  

}

模型登录:

    public function login($username,$password){
    $this->db->where('LoginCliente',$username);
    $this->db->where('PassCliente',$password);
    $q = $this->db->get('clientes');
    if($q->num_rows()>0){
        return true;
    }else{
        return false;
    }

}

插入控制器:

  public function insert(){

  $post = $this->input->post();
  $this->load->model('file');
  $file_name = $this->file->UploadImage();
  $post['file_name'] = $file_name;

  $bool = $this->cotizacion->insert($post);
  if($bool){
     header("Location: " . base_url() . "profile"); 
  }else{
    header("Location: " . base_url() . "article/nuevo"); //no se guardo
  }

  }

这是插入模型:

    public function insert($post = null){

    if($post != null){
    $tipotrabajo = $post['tipotrab'];
    $origenmaterial = $post['origenmat'];
    $material = $post['material'];
    $alto = $post['alto'];
    $ancho = $post['ancho'];
    $largo = $post['largo'];
    $cantidad = $post['cantidad'];
    $descripcion = $post['descripcion'];
    $file_name = $post['file_name'];

    $SQL = "INSERT INTO cotizaciones(IdCotizacion,IdCliente,
    FechaCotizacion,TipoTrabajo,OrigenMaterial,
    Material,Alto,Ancho,Largo,Cantidad,Descripcion,img,Estado)
    VALUES (null,2,curdate(),'$tipotrabajo','$origenmaterial',
    '$material','$alto','$ancho','$largo','$cantidad',
    '$descripcion','$file_name','En espera');";

     if($this->db->query($SQL)){
     return true;
     }
     }
      return false;  
     }

实际上我在字段 IdCliente 中插入了数字2但我需要插入相应的id-&gt;值(NULL, 2

0 个答案:

没有答案