用户
 找回密码
 入住 CI 中国社区
搜索
查看: 5619|回复: 13
收起左侧

[已解决] URL传参问题

[复制链接]
发表于 2010-4-8 15:56:53 | 显示全部楼层 |阅读模式
控制器代码
function news($id)
{
$sql="select * from news where id=$id";
}
地址localhost/news/123.html 正常
localhost/news/.html没参数报错 怎么处理这快?
发表于 2010-4-8 17:29:38 | 显示全部楼层
function news($id)
{
if(!is_numeric($id))die('error');
$sql="select * from news where id=$id";
}
楼主不做判断的吗?
发表于 2010-4-8 19:00:01 | 显示全部楼层
报什么错?
 楼主| 发表于 2010-4-9 15:19:01 | 显示全部楼层
我说的不是那个意思 那个判断已经做了 是否是数字  参数为空的时候怎么弄
发表于 2010-4-9 15:54:10 | 显示全部楼层
你的例子中$id就是123的意思是吗?如果是那就判断当$id为空时redirect转向到指定的页面,不知道是不是你要的
 楼主| 发表于 2010-4-10 12:15:59 | 显示全部楼层
参数为空会报错
发表于 2010-4-10 12:18:17 | 显示全部楼层
为空当然会报错了,sql语法错误啊
所以说要判断啊,先判断有没有这个值,没有提示错误或转向或给定默认值,存在在判断是否符合相应的数据类型
发表于 2010-4-10 15:55:05 | 显示全部楼层
我问报什么错?????
 楼主| 发表于 2010-4-10 23:09:36 | 显示全部楼层
http://www.jzpkw.com/index.php/news/details/6.html
变成http://www.jzpkw.com/index.php/news/details/.html
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  Missing argument 1 for News::details()</p>
<p>Filename: controllers/news.php</p>
<p>Line Number: 45</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Undefined variable: id</p>
<p>Filename: controllers/news.php</p>
<p>Line Number: 47</p>

</div>
 楼主| 发表于 2010-4-12 13:13:52 | 显示全部楼层
怎么没人回答了 。。。。。。。。。。

本版积分规则