我想知道为什么会出现此错误消息。列'用户名'不能为空 ?
我将Null设为No。
发生数据库错误
错误号码:1048
列'用户名'不能为空
INSERT INTO
login
(username
,password
,role
)价值观 (NULL,NULL, ' $ 2y $ 10 $ FaVW7V1yEDB0NnlmgwPHQ.SQi34ZCXi9ABJDOebDflZ.cqcSwZAoW',NULL)文件名:C:/ Program 文件/的EasyPHP-Devserver-16.1 / EDS-WWW / companygiondaci /系统/数据库/ DB_driver.php
行号:691
视图/ addusers.php
<div class="row-fluid">
<div class="span12">
<?php $this->load->library('form_validation'); ?>
<?php echo $successmessage; ?>
<?php echo validation_errors(); ?>
<?php echo form_open('cpages/addusersdb'); ?>
<div class="widget-box">
<div class="widget-title"><h5>Add User</h5></div>
<div class="widget-content">
<table border="0" style="width: 100%; height: 90px;">
<tr>
<td>USERNAME</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>EMAIL</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td>PASSWORD</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td>ROLE</td>
<td><?php echo form_dropdown('roles', $options, 'administrator'); ?></td>
</tr>
<tr>
<td></td>
<td><input type="submit" class="edit" value="ADD"></td>
</tr>
</table>
</div>
</div>
</div>
</div>
模型/ Mpages.php
public function add_user()
{
$options = [
'roles' => 'administrator',
];
$hash = password_hash($this->input->post('password'), PASSWORD_BCRYPT, $options);
$data = array(
'username' => $this->input->post('username'),
'email' => $this->input->post('email'),
'password' => $hash,
'role' => $this->input->post('roles')
);
return $this->db->insert('login', $data);
}
答案 0 :(得分:1)
if($this->input->post()) {
$hash = password_hash($this->input->post('password'), PASSWORD_BCRYPT, $options);
$data = array(
'username' => $this->input->post('username'),
'email' => $this->input->post('email'),
'password' => $hash,
'role' => $this->input->post('roles')
);
$this->YOUR_MODEL->add_user($data);
}
这应该进入你的控制器。
你的模型功能应该是这样的
public function add_user($data)
{
return $this->db->insert('login', $data);
}
答案 1 :(得分:0)
嗯,你说:我将Null设置为否。这意味着这将不允许NULL值,但你发送的是NULL值......?