0
フォームのデータをコントローラに渡したいが、そこからデータベースに保存したいが、コントローラのデータを保存しようとすると空です。CodeIgniterでフォームからコントローラにデータが渡されない
VIEWページ
<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 }
$ data = array( "name" => $ this-> input-> post( 'age')、 "name" => $ this-> input-> post( 'age '))); –
@ Yaseen上記の例で使用した配列にプッシュする方法は問題ありません。 $ this-> input-> post ['phno']の使い方が間違っています。これは$ this-> input-> post( 'phno')です。 –
あなたが書いたたくさんのコードはうまくいきます –