2016-01-31 106 views
1

所以我想提出一個形式供人註冊,但其沒有工作,出於某種原因,我在NetBeans調試器不工作,所以我不能正確檢查。使代碼點火登記表

這是HTML表單

<?php 

     if(validation_errors() != false) 
     { 
      echo '<div class="form-group alert alert-danger alert-box has-error">'; 
       echo'<ul>'; 
        echo validation_errors('<li class="control-label">', '</li>'); 
       echo'</ul>'; 
      echo '</div>'; 
     } 

     /* form-horizontal */ 

     echo form_open('main/insertInformation'); 

     ?> 

    <div class="form-group"> 
     <input type="text" name="name" class="form-control input-lg" placeholder="Name"> 
    </div> 
    <div class="form-group"> 
     <input type="email" name="email" class="form-control input-lg" placeholder="Email"> 
    </div> 
    <div class="form-group"> 
     <input type="text" name="phone" class="form-control input-lg" placeholder="Phone"> 
    </div> 
    <div class="form-group"> 
     <input type="password" name="password" class="form-control input-lg" placeholder="Password"> 
    </div> 
    <div class="form-group"> 
     <input type="password" name="password_confirm" class="form-control input-lg" placeholder="Confirm Password"> 
    </div> 
    <div class="form-group"> 
     <button type='submit' class="btn btn-primary btn-lg btn-block">Sign In</button> 
    </div> 
</div> 

然後我試圖讓所有這些信息到我的控制器這樣

public function insertInformation(){ 
       $this->load->helper('form'); 
       $this->load->library('form_validation'); 

       $this->form_validation->set_rules('name', 'Name', 'required'); 
       $this->form_validation->set_rules('email', 'Email', 'required'); 
       $this->form_validation->set_rules('phone', 'Phone', 'required'); 
       $this->form_validation->set_rules('password', 'Password', 'required|min_length[4]|max_length[32]'); 
       $this->form_validation->set_rules('password_confirm', 'Password Confirm', 'required|matches[password]'); 


       if ($this->form_validation->run() == FALSE){ 
       $this->load->view('header_view'); 
       $this->load->view('login_view'); 
       $this->load->view('footer_view'); 
       }else{ 

        $data = array(
        'name' => $this->input->post('name'), 
        'email' => $this->input->post('email'), 
        'phone' => $this->input->post('phone'), 
        'password' => $this->input->post('password') 

       ); 
        $this->db->trans_begin(); 
       $this->load->model('main_page'); 
       $this->main_page->storeRegisterInfo($data); 

       $message['account_created'] = 'Your account has been created'; 
       $this->load->view('admin_view', $message); 
       } 
      } 

這裏是模型,

public function storeRegisterInfo($data){ 
      $insert = $this->db->insert('new_users',$data); 
      return $insert; 

     } 

和我的數據庫看起來像這樣 enter image description here

我非常新的笨,所以我敢肯定有很多錯誤的位置,所以請不要幫我,並請你解釋我在更好地理解步驟。謝謝!

這是錯誤 enter image description here

+1

旁註:我看到'varchar(20)'爲你的密碼列,這告訴我你沒有使用足夠安全的密碼哈希函數或者如果使用了一個。如果這個網站是活的或打算上線,你不應該這樣做。現在,你有沒有使用CI的錯誤報告? https://ellislab.com/codeigniter/user-guide/general/errors.html,你是否檢查對您的查詢錯誤? –

+1

不工作????什麼不工作PLZ添加錯誤 – devpro

+1

@devpro如果在未來5-10分鐘內OP沒有響應。那麼他們要麼現在檢查,要麼期待一個*魔術答案*。後者不會發生;不是來自* moi *。 ;-) –

回答

1

除去這一部分,都應該工作,然後

$this->db->trans_begin(); 
+0

我在最後的評論中告訴他刪除了這個閱讀我們的聊天 – devpro

+0

http://chat.stackoverflow.com/rooms/102177/discussion-between-devpro-and-masnad-nihit – devpro

3

對於特異性針對此錯誤長時間的討論後,只有你錯過了加載需要加載你的模型作爲模型:

$this->load->model('main_page'); 

(更新版) :去除的$this->db->trans_begin();

解決您的問題,但我認爲它不完整的解決方案。

如果要使用交易,請確保只能將此應用於InnoDBBDB表格類型不適用於MyISAM

如果您使用InnoDB並希望使用t rans_begin()而不是確保執行完所有查詢後您需要使用trans_commit()否則這將不會在您的數據庫中顯示任何內容。

From the User Guide:

$this->db->trans_begin(); // transaction start 

$this->db->query('AN SQL QUERY...'); 

if ($this->db->trans_status() === FALSE) 
{ 
    $this->db->trans_rollback(); // rollback if failure 
} 
else 
{ 
    $this->db->trans_commit(); // commit if success 
} 
1

當我們寫一個模型文件,我們有組條件。其中之一就是模型文件應包含_model字。 (例:user_modelregistration_model

所以,你的模型應該也可以改變。現在,你的模型看起來像main_page改變它,(例如:main_modelpage_model)。


文件名應該Main_model.php

內部模型

class Main_model extends CI_Model { 

     public function __construct() 
     { 
       parent::__construct(); 
     } 

} 

This is how Codeigniter use the Model.

+0

該文檔實際上沒有說它需要是* _model。 – TurtleTread

+0

是的,但你的工作沒有改變。 – devpro