php - CodeIgniter not submitting form values to database -
setting "method" attribute of form fixed me, submitting database fine, now, have similar problem validating credentials maybe has same root problem since forgot method in first place, thank much.
i have problem while attempting learn codeigniter , general mvc principles.
i have sign form view
<div class="container"> <form class="form-horizontal" style="width:500px;" action="sign_up"> <fieldset> <!-- form name --> <legend>sign up</legend> <!-- text input--> <div class="control-group"> <label class="control-label" for="username">username</label> <div class="controls"> <input id="username" name="username" placeholder="username" class="input-xlarge" required="" type="text"> <p class="help-block">your username</p> </div> </div> <!-- text input--> <div class="control-group"> <label class="control-label" for="email_address">email</label> <div class="controls"> <input id="email_address" name="email_address" placeholder="email address " class="input-xlarge" required="" type="text"> <p class="help-block">enter email address</p> </div> </div> <!-- text input--> <div class="control-group"> <label class="control-label" for="first_name">first name</label> <div class="controls"> <input id="first_name" name="first_name" placeholder="first name" class="input-xlarge" required="" type="text"> <p class="help-block">enter first name</p> </div> </div> <!-- text input--> <div class="control-group"> <label class="control-label" for="last_name">last name</label> <div class="controls"> <input id="last_name" name="last_name" placeholder="last name" class="input-xlarge" type="text"> <p class="help-block">help</p> </div> </div> <!-- password input--> <div class="control-group"> <label class="control-label" for="password">password input</label> <div class="controls"> <input id="password" name="password" placeholder="password" class="input-xlarge" required="" type="password"> <p class="help-block">help</p> </div> </div> <div class="control-group"> <label class="control-label" for="password">password confirmation</label> <div class="controls"> <input id="password2" name="password2" placeholder="password" class="input-xlarge" required="" type="password"> <p class="help-block">help</p> </div> </div> <!-- button --> <div class="control-group"> <label class="control-label" for="singlebutton"></label> <div class="controls"> <button class="btn btn-success" onclick="submit" >sign up</button> </div> </div> </fieldset> </form> </div>
which submits (user/)sign_up
public function sign_up() { $this->load->model('login_model'); if($query = $this->login_model->create_member()){ $data['main_content'] = 'user_login_view'; $this->load->view('template', $data); } }
and passes model function "create_member"
function create_member() { $newdata = array( 'user_name' => $this->input->post('username'), 'password' => md5($this->input->post('password')), 'email' => $this->input->post('email_address'), 'first_name' => $this->input->post('first_name'), 'last_name' => $this->input->post('last_name') ); $insert = $this->db->insert('users', $newdata); return $insert; }
i believe have correct table set , following mvc principle.
id int(11) user_name varchar(25) password varchar(32) email varchar(50) first_name varchar(32) last_name varchar(32)
my problem password value passing on database rest submits 0, suggestions or obvious mistakes point out?
id user_name password email first_name last_name 20 0 d41d8cd98f00b204e9800998ecf8427e 0 0 0
thank
i suggest change form open tag explicitly call controller, , need include method="post"
attribute form post. e.g.
<form class="form-horizontal" style="width:500px;" action="/user/sign_up" method="post">
if wanted use ci's form helper, use following:
$attributes = array('class' => 'form-horizontal', 'style' => 'width:500px;'); echo form_open('user/sign_up', $attributes);
Comments
Post a Comment