URL传参问题
控制器代码function news($id)
{
$sql="select * from news where id=$id";
}
地址localhost/news/123.html 正常
localhost/news/.html没参数报错 怎么处理这快? function news($id)
{
if(!is_numeric($id))die('error');
$sql="select * from news where id=$id";
}
楼主不做判断的吗? 报什么错? 我说的不是那个意思 那个判断已经做了 是否是数字参数为空的时候怎么弄 你的例子中$id就是123的意思是吗?如果是那就判断当$id为空时redirect转向到指定的页面,不知道是不是你要的 参数为空会报错 为空当然会报错了,sql语法错误啊
所以说要判断啊,先判断有没有这个值,没有提示错误或转向或给定默认值,存在在判断是否符合相应的数据类型 我问报什么错????? 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> 怎么没人回答了 。。。。。。。。。。
页:
[1]
2