layui的select导致form提交的值全为空
本帖最后由 ufo233 于 2020-2-25 11:59 编辑将select删除就能获取到其他input控件的值,但加上就input的值全部为空
//layui的select
<label class="layui-form-label">类型</label>
<div class="layui-input-inline">
<select name="cid" >
<?php foreach ($category as $val) { ?>
<option value="<?php echo $val['cid'] ?>" ><?php echo $val['catename'] ?></option>
<?php } ?>
</select>
</div>
//Controller
public function ins_art(){
$cid1 = $this->input->get_post('cid');
$title = $this->input->post('title');
$description = $this->input->post('description');
$content = $this->input->post('content');
$time = time();
$author = $this->input->post('author');
$info = array('cid' => $cid1,'title' => $title,'description' => $description,'content' => $content,'createtime' => $time,'author' => $author);
if($this->Model_admin->insert_art($info))
{
redirect('Admin/ins_art');
}
} 本帖最后由 ufo233 于 2020-2-26 16:27 编辑
请看这里 (稍后上传图片代码)
***今天发现并不是<select>所造成的错误,我试了input标签,或直接在控制器的方法中赋值给变量(对应下方列名cid的变量),也会报错(错误在下方)
***当我查询数据库的时候,发现数据是插入成功的,虽然报错,但数据成功插入数据库
//错误 使用input标签
Error Number: 1048
Column 'cid' cannot be null
INSERT INTO `article` (`cid`, `title`, `description`, `content`, `createtime`, `author`) VALUES (NULL, NULL, NULL, NULL, 1582602909, NULL)
Filename: D:/Appserv/www/php/system/database/DB_driver.php
Line Number: 691
//错误 直接赋值
Error Number: 1048
Column 'cid' cannot be null
INSERT INTO `article` (`cid`, `title`, `description`, `content`, `createtime`, `author`) VALUES (1, NULL, NULL, NULL, 1582602909, NULL)
Filename: D:/Appserv/www/php/system/database/DB_driver.php
Line Number: 691
***但当我不获取($cid = $this->input->post('cid');)属于cid的input标签的值时,就能获取其他input标签的值
//错误 不获取属于cid的input
Error Number: 1048
Column 'cid' cannot be null
INSERT INTO `article` (`cid`, `title`, `description`, `content`, `createtime`, `author`) VALUES (NULL, ‘测试’, ‘测试’, ‘测试’, 1582602909, ‘测试’)
Filename: D:/Appserv/www/php/system/database/DB_driver.php
Line Number: 691
页:
[1]