Home > Backend Development > PHP Tutorial > thinkPHP3.2.3问题

thinkPHP3.2.3问题

WBOY
Release: 2016-06-20 12:44:08
Original
871 people have browsed it

小白我最近刚学thinkphp3.2.3,,准备做毕业设计,现在卡在一个问题上。
该模块可以添加数据就是修改和删除不了,不知道怎么解决。望大神解救。
不知道是不是传入的参数有问题
数据表

CREATE TABLE IF NOT EXISTS `item` (  `inumber` smallint(3) unsigned zerofill NOT NULL AUTO_INCREMENT COMMENT '项目编号',  `iname` varchar(64) CHARACTER SET latin1 NOT NULL COMMENT '项目名称',  `quantity` smallint(2) DEFAULT '1' COMMENT '参赛人数(>1表示团体项目)',  `proportion` smallint(6) NOT NULL COMMENT '参赛规模',  PRIMARY KEY (`inumber`),  UNIQUE KEY `itemNumber` (`inumber`)) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COMMENT='项目' AUTO_INCREMENT=6 ;
Copy after login


控制器
        public function update($inumber)        {            //默认显示添加表单            if (!IS_POST) {                $model = M('item')->where('inumber='.$inumber)->find();                $this->assign('item',$model);                $this->display();            }            if (IS_POST) {                $model = D("item");                if (!$model->create()) {                    $this->error($model->getError());                }else{                    if ($model->save()) {                        $this->success("更新成功", U('Item/index'));                    } else {                        $this->error("更新失败");                    }                }            }        }
Copy after login


<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title></title></head><body><form method="post" action="{:U('Item/update?inumber=')}{$item.inumber}">    <div class="form-group">        <label>项目名</label>        <input type="text" name="iname" class="form-control" value="{$item.iname}"  placeholder="输入项目名">        <label >参赛人数</label>        <select name="quantity">            <option value="1">1</option>            <option value="2">2</option>            <option value="3">3</option>            <option value="4">4</option>            <option value="5">5</option>            <option value="6">6</option>            <option value="7">7</option>            <option value="8">8</option>            <option value="9">9</option>            <option value="10">10</option>            <option value="11">11</option>            </select>        <label>参赛单位数</label>            <input type="text" name="proportion" class="form-group" value="{$item.proportion}"  placeholder="输入参赛单位数">    <input type="hidden" name="inumber" value="{$item.inumber}">    <button type="submit">提交</button>           </div></form></body></html>
Copy after login


回复讨论(解决方案)

控制器 14行 你少了where条件

if($model->where('inumber='.I('inumber'))->save() !==false){   $this->success(‘修改成功’);}else{   $this->error('修改失败!')}
Copy after login
Copy after login

if($model->where('inumber='.I('inumber'))->save() !==false){   $this->success(‘修改成功’);}else{   $this->error('修改失败!')}
Copy after login
Copy after login


我改了还是不行,改成I('post.inumber')也不行

忘了贴入口了

 <foreach name="model" item="v">            <tr>                <td>{$v.inumber}</td>                <td>{$v.iname}</td>                <td>{$v.quantity}</td>                <td>{$v.proportion}</td>                <td><a href="{:U('item/update?inumber=')}{$v.inumber}">编辑</a> | <a href="{:U('item/delete?inumber=')}{$v.inumber}" style="color:red;" onclick="javascript:return del('您真的确定要删除吗?\n\n删除后将不能恢复!');">删除</a></td>            </tr>        </foreach>
Copy after login

解决了!!!是入口路由出错了

                <td><a href="{:U('item/update?inumber=')}{$v.inumber}">编辑</a> | <a href="{:U('item/delete?inumber=')}{$v.inumber}" style="color:red;" onclick="javascript:return del('您真的确定要删除吗?\n\n删除后将不能恢复!');">删除</a></td>
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template