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

传递数据出错了吗?

[复制链接]
发表于 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 Occurred

Error Number: 1064

You 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 1

17

Filename: C:\wamp\www\ci\system\database\DB_driver.php

Line Number: 330



发表于 2012-8-26 01:10:43 | 显示全部楼层
$sql = 'select * from entries where id = '+$id;

=》

$sql = 'select * from entries where id = '.intval($id);
 楼主| 发表于 2012-8-28 19:26:05 | 显示全部楼层
太尉天上飞 发表于 2012-8-26 01:10
$sql = 'select * from entries where id = '+$id;

=》

谢谢~
发表于 2012-8-28 19:36:59 | 显示全部楼层
链接字符串问题,“+”是js链接字符串;“.”是php程序链接字符串。。。。

本版积分规则