2017-08-08 110 views
0

这是登录如何这种输入形式插入到我的数据库

<!-- Signin Small Modal--> 
    <div class="modal fade bd-example-modal-sm" id="mySignModal" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true"> 
    <!--<div class="modal fade bd-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">--> 
     <div class="modal-dialog modal-sm" role="document"> 
     <div class="modal-content"> 
      <div class="modal-header btn-primary"> 
      <h5 class="modal-title">Sign-in</h5> 
      <!--<button type="button" class="close" data-dismiss="modal" aria-label="Close"> 
       <span aria-hidden="true">&times;</span> 
      </button>--> 
      </div> 
      <div class="modal-body"> 
      <form id="signinForm" action="" method="post"> 
       <input type="hidden" name="txtId" value="0"> 
       <div class="form-group"> 
       <label for="txtUsername" style="font-size: 12px;">Username</label> 
       <input type="text" class="form-control" name="txtUsername" placeholder="Enter username"> 
       <!--<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>--> 
       </div> 
       <div class="form-group"> 
       <label for="txtEmail" style="font-size: 12px;">Email</label> 
       <input type="email" class="form-control" name="txtEmail" aria-describedby="emailHelp" placeholder="Enter email"> 
       <!--<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>--> 
       </div> 
       <div class="form-group"> 
       <label for="txtPassword" style="font-size: 12px;">Password</label> 
       <input type="password" class="form-control" name="txtPassword" placeholder="Password"> 
       </div> 
       <div class="form-group"> 
       <label for="txtConfirmPass" style="font-size: 12px;">Confirm Password</label> 
       <input type="password" class="form-control" name="txtConfirmPass" placeholder="Password"> 
       </div> 
      </form> 
      </div> 
      <div class="modal-footer"> 
      <button type="button" id="btnRegister" class="btn-sm btn-success">Submit</button> 
      <button type="button" class="btn-sm btn-secondary" data-dismiss="modal">Close</button> 
      </div> 

     </div> 
     </div> 
    </div> 

模态下的,这是我的JavaScript从情态动词输入插入到我的数据库

<script> 

     $(function(){ 

      $('#btnCreateAccount').click(function(){ 
       $('#mySignModal').modal('show'); 
      }); 

      $('#btnRegister').click(function(){ 
       $('#mySignModal').find('.modal-title').text('Sign-in'); 
       $('#signinForm').attr('action', '<?php echo base_url() ?>index.php/login/addUsers'); 
      }); 

     }); 
    </script> 

这是我登录控制器

public function addUsers(){ 
     $result = $this->em->addUsers(); 
     $msg['success'] = false; 
     $msg['type'] = 'add'; 
     if($result){ 
      $msg['success'] = true; 
     } 
     echo json_encode($msg); 
    } 

,这是我的用户模型

public function addUsers(){ 
     $field = array(
      'username'=>$this->input->post('txtUsername'), 
      'email'=>$this->input->post('txtEmail'), 
      'password'=>$this->input->post('txtPassword') 
      //'created_at'=>date('Y-m-d H:i:s') 
      ); 

     /*$field = array(
      'username'=>'hardcoded username', 
      'email'=>'hardcoded email', 
      'password'=>'hardcoded email' 
      //'created_at'=>date('Y-m-d H:i:s') 
      );*/ 

     $this->db->insert('users', $field); 
     if($this->db->affected_rows() > 0){ 
      return true; 
     }else{ 
      return false; 
     } 
    } 

它不会让我插入数据从登录模式到我的数据库,它不会让我当我检查网址http://localhost/ci_testblog/index.php/login/addUsers它说:

数据库出错

错误号:1048

列 '用户名' 不能为空

INSERT INTO usersusernameemailpassword)VALUES(NULL, NULL,NULL)

文件名:C:/xampp/htdocs/ci_testblog/system/database/DB_driver.php

行号:691

什么这个可能是错的吗?

+1

表单标签的动作你可以设置你的数据库表字段值**默认NULL * *。 –

+0

我会建议插入一个用户名然后。 @ NikunjRathod-为什么地球上的用户名应该适当地为空? – ggdx

+0

您是否尝试“回显”您的** $ this-> input-> post('txtUsername')**以查看他们是否有一些数据 – Mary

回答

0

首先,你必须检查值是包括在阵列中或没有的print_r($场);因为在你的值中,所有的字段在数据库错误中都是空的。你也必须在数据库中为列设置一个默认值。由于

0

请带模式按钮输入类型=“提交” insted的输入类型=“按钮”的给控制器的功能模态

相关问题