我正在开发一个系统,但我在注册页面上遇到了问题。成员数据无法输入数据库。没有消息错误 这是我的观点
<?php $this->load->view('notification') ?>
<form method="post" action="<?php echo base_url('register/post') ?>">
<div class="input-place">
<label>
Kartu Pengenal
<span class="required">*</span>
</label>
<select name="kartupengenal" id="show" onchange="sesuaikantandapengenal(this.value)">
<option selected="selected">-- Pilih Salah Satu--</option>
<?php foreach($kartupengenal as $row): ?>
<option value="<?php echo $row['identitasid'] ?>"><?php echo $row['nama'] ?></option>
<?php endforeach ?>
</select>
</div>
<div class="input-place">
<label>
No Identitas
<span class="required">*</span>
</label>
<input type="text" id="ktp" class="form-control" name="noidentitas" style="display:none">
<input type="text" id="sim" class="form-control" name="noidentitas" style="display:none">
<input type="text" id="ktm" class="form-control" name="noidentitas" style="display:none">
<input type="text" id="passport" class="form-control" name="noidentitas" style="display:none">
</div>
<button type="submit" class="btn btn-default btn-primary">Daftar</button>
</form>
然后是这个控制器
//controller code register.php
public function post()
{
$this->form_validation->set_error_delimiters('<div class="alert alert-error">', '</div>');
if($this->_validation()==FALSE){
redirect(base_url('register'));
$this->session->set_flashdata('error', 'Pendaftaran gagal, silahkan coba kembali!');
}else{
$data = array( 'identitas' => $this->input->post('kartupengenal'),
'noidentitas' => $this->input->post('noidentitas')
);
$this->model_user->post($data);
$this->session->set_flashdata('success', 'Pendaftaran berhasil');
redirect(base_url('auth/login'));
}
}
public function _validation(){
$this->form_validation->set_rules('kartupengenal','Nama Panggilan', 'trim|required|xss_clean');
$this->form_validation->set_rules('noidentitas','Nomor Identitas', 'numberic|trim|required|xss_clean');
return $this->form_validation->run();
}
$this->form_validation->set_rules('noidentitas','Nomor Identitas', 'numberic|trim|required|xss_clean');
- &gt;它只保存identitasid的最后一个id,如果我选择identitas id 1直到3它不能保存数据。如何修复它?
提前感谢
答案 0 :(得分:0)
mybe这段代码可以帮到你。 代码:视图
<form action="http://heloo.com/contact" method="post">
<fieldset>
{error_msg}
<div class="form-group">
<input type="text" name="name" class="form-control" placeholder="Name*">
</div>
<div class="form-group">
<input type="email" name="email" class="form-control" placeholder="E-mail*">
</div>
<div class="form-group">
<input type="text" name="subject" class="form-control" placeholder="Subject*">
</div>
<div class="form-group">
<textarea name="message" class="form-control" rows="7" placeholder="Message*"></textarea>
</div>
<button type="submit" class="btn btn-info btn-cons">Send Message</button>
</fieldset>
</form>
代码:controller
public function contact() {
if($_SERVER['REQUEST_METHOD'] === 'POST') {
$this->load->library('form_validation'); //Load library.
$this->form_validation->set_rules('name', 'Username', 'required|min_length[1]|max_length[45]|xss_clean');
$this->form_validation->set_rules('email', 'E-mail', 'required|min_length[1]|max_length[100]|valid_email|xss_clean');
$this->form_validation->set_rules('subject', 'Subject', 'required|min_length[1]|max_length[45]|xss_clean');
$this->form_validation->set_rules('message', 'Message', 'required|xss_clean');
if ($this->form_validation->run() == TRUE) {
$this->load->model('Contact_Us');
$input['i_name'] = $this->input->post('name', TRUE);
$input['i_email'] = $this->input->post('email', TRUE);
$input['i_subject'] = $this->input->post('subject', TRUE);
$input['i_message'] = $this->input->post('message', TRUE);
$this->Contact_Us->save_contact($input);
}else {
//Set error message.
$this->session->set_flashdata('error_msg', validation_errors());
redirect('contact');
}
}else {
//another code
}
}
代码:模型
public function save_contact($input = array()) {
$this->db->set('t_name', $input['i_name']);
$this->db->set('t_email', $input['i_email']);
$this->db->set('t_subject', $input['i_subject']);
$this->db->set('t_message', $input['i_message']);
$this->db->insert('contact');
}
请在此处阅读此文档:
https://ellislab.com/codeigniter/user-guide/database/configuration.html
https://ellislab.com/codeigniter/user-guide/database/connecting.html
https://ellislab.com/codeigniter/user-guide/database/active_record.html
https://ellislab.com/codeigniter/user-guide/libraries/form_validation.html
https://ellislab.com/codeigniter/user-guide/general/models.html
答案 1 :(得分:-1)
检查每个帖子的值是否在表单帖子上回显。
1378-3640/? I/GLSUser﹕ [GLSUser] getTokenFromCache: [account: <ELLIDED:2885>, callingPkg: com.google.android.gms, service: oauth2:https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/pos]
1378-3640/? I/Auth.Core﹕ [TokenCache] Missing snowballing token: no granted scopes set.
1378-3640/? I/GLSUser﹕ [GLSUser] getTokenFromGoogle [account: <ELLIDED:2885>, callingPkg: com.google.android.gms, service: oauth2:https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/pos
6376-6376/com.myapp.android D/AndroidRuntime﹕ Shutting down VM
6376-6376/com.myapp.android W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41fced40)
6376-6376/com.myapp.android I/Process﹕ Sending signal. PID: 6376 SIG: 9