2016-05-02 15 views
0

Ich möchte Daten aus einem Formular an meinen Controller übergeben und von dort möchte ich sie in meiner Datenbank speichern, aber wenn ich versuche, die Daten in der Steuerung das Array zu speichern ist leer.Daten nicht vom Formular zum Controller in CodeIgniter

ANSICHT SEITE

<form method="post" action="<?php echo base_url();? >index.php/users/save_record"> 
    <div class="form-group"> 
     <label for="usr">Name:</label> 
     <input type="text" class="form-control" name="name" id="name"> 
    </div> 
    <div class="form-group"> 
     <label for="pwd">Age:</label> 
     <input type="text" class="form-control" name="age" id="age"> 
    </div> 
    <div class="form-group"> 
     <label for="pwd">Sex:</label> 
     <input type="text" class="form-control" name="sex" id="sex"> 
    </div> 
    <div class="form-group"> 
     <label for="pwd">Phone Number:</label> 
     <input type="text" class="form-control" name="phno" id="phno"> 
    </div> 
    <div class="form-group"> 
     <input class="btn btn-primary" type="submit" name="submit" value="Send" /> 
    </div> 
</form> 

CONTROLLER

public function save_record() 
    { 
     if ($this->input->post('submit')==true) 
     { 
     $udata['name']=$this->input->post['name']; 
     $udata['age']=$this->input->post['age']; 
     $udata['sex']=$this->input->post['sex']; 
     $udata['phno']=$this->input->post['phno']; 
     //$this->Users_model->save_user($udata);  
     var_dump($udata); 
     } 
    } 

RESULT

array(4) { ["name"]=> NULL ["age"]=> NULL ["sex"]=> NULL ["phno"]=> NULL } 
+0

erstellen Array wie diese $ data = array ("name" => $ this-> Input-> post ('Alter'), "name" => $ this-> Input-> post ('Alter ')); –

+0

@Yaseen die Methode des Pushing zu einem Array im obigen Beispiel ist in Ordnung. die Verwendung von $ this-> input-> post ['phno'] ist falsch, sollte $ this-> input-> post ('phno') sein; –

+0

Vielen Dank .... Code, den Sie geschrieben haben, funktioniert gut –

Antwort

1

Ihre Syntax ist falsch. Versuche dies.

if ($this->input->post('submit') == true) { 
    $udata['name'] = $this->input->post('name'); 
    $udata['age'] = $this->input->post('age'); 
    $udata['sex'] = $this->input->post('sex'); 
    $udata['phno'] = $this->input->post('phno'); 
    //$this->Users_model->save_user($udata);  
    var_dump($udata); 
} 
Verwandte Themen