狮子座百分之99 发表于 2012-8-24 23:03:39

传递数据出错了吗?

view中: 标题:<?=anchor("message/enter/$row->id","$row->title");?>
点击后url:http://localhost/ci/index.php/message/enter/17,controller的enter():
$id = $this->uri->segment(3);
$sql = 'select * from entries where id = '+$id;
$data['message'] = $this->db->query($sql);
出现错误:
A Database Error OccurredError Number: 1064You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '17' at line 117Filename: C:\wamp\www\ci\system\database\DB_driver.phpLine Number: 330

太尉天上飞 发表于 2012-8-26 01:10:43

$sql = 'select * from entries where id = '+$id;

=》

$sql = 'select * from entries where id = '.intval($id);

狮子座百分之99 发表于 2012-8-28 19:26:05

太尉天上飞 发表于 2012-8-26 01:10 static/image/common/back.gif
$sql = 'select * from entries where id = '+$id;

=》


谢谢~

守望幸福的孩子 发表于 2012-8-28 19:36:59

链接字符串问题,“+”是js链接字符串;“.”是php程序链接字符串。。。。
页: [1]
查看完整版本: 传递数据出错了吗?