我目前有一個窗體,其中包含一個從數據庫中提取菜單項的下拉菜單。 我期望實現的是允許用戶選擇這些值中的一個並將其添加到數據庫。表單目前正在提交併正確插入,但數據庫除外。當我嘗試將下拉值添加到數據庫時,所有輸入都會返回爲空。如果我把它拿出來,它可以正常工作。使用代碼點火器將下拉值提交到數據庫
<form name = "form1" id = "form1" method ="post"> <!--action="<?php echo base_url()."index.php/Admin/create_user"; ?>"-->
<?php echo validation_errors(); ?>
<label for="first_name" class = "labelForm">First Name:</label>
<input type="text" id="first_name" name="first_name" class = "input2">
<label for="last_name" class = "labelForm">Last Name:</label>
<input type="text" id="last_name" name="last_name" class = "input2">
<label for="username" class = "labelForm">Username:</label>
<input type="text" id="username" name="username" class = "input2" onblur="check_if_exists();">
<label for="password" class = "labelForm">Password:</label>
<input type="password" id="password" name="password" class = "input2" onblur="validatePassword();">
<label for="passconf" class = "labelForm">Password:</label>
<input type="password" id="passconf" name="passconf" class = "input2" onblur="checkPasswords();">
<label for="email" class = "labelForm">Email:</label>
<input type="text" id="email" name="email" class = "input2">
<!-- <label for="hospital" class = "labelForm">Hospital:</label>
<select name="product" class = "input2" id = "hospitals">
<option selected disabled hidden style='display: none' value=''></option>
<?php foreach($hospital_dropdown as $option){?>
<option id = "hospitals" name="hospitals" value="<?php $option->hospitalName;?>"> <?php print_r($option->hospitalName); ?> </option>
<?php }?>
</select>-->
<label for="hospitals" class = "labelForm">Hospital:</label>
<select name="product" class = "input2" id = "hospitals">
<?php foreach($hospital_dropdown as $index => $option):?>
<option id = "hospitals_<?=$index?>"
name="hospitals"
value="<?=$option->hospitalName;?>"
><?=$option->hospitalName;?></option>
<?php endforeach;?>
</select>
<button type="button" id = "new_user_submit">Add New User</button>
</form>
控制器:
function create_user(){
$this->load->model('User_model');
$password = $this->input->post('password');
$hash = $this->bcrypt->hash_password($password);
$data = array(
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'username' => $this->input->post('username'),
'password' => $hash,
'class' => $this->input->post('userclass'),
'hospital' => $this->input->post('hospitals'),
'email' => $this->input->post('email'),
);
$this->User_model->create_user($data);
$username = $this->session->userdata('username');
$data['hospital_dropdown'] = $this->User_model->hospital_dropdown();
$data['main_content'] = 'admin';
$this->load->view('includes/admin/template', $data);
}
型號:
function create_user($data){
$insert = $this->db->insert('users', $data);
return $insert;
}
如果我拿出在其提交罰款,但是當我離開它,所有的字段回來控制器醫院部分爲空並且不會提交。 任何想法? 謝謝!
你傳球之前先查看vae_dump所有值? –
@FaisalMehmoodAwan值被成功添加到下拉菜單,只是將它們添加到數據庫中的問題是目前的問題 – user