新手,第一次做新闻发布,在新闻浏览界面的时候出现了问题
以下是在网上看到的一种写法include "connect.php";
$id=$_GET["id"];
$query="SELECT * from news Where id=".$id;
$result=mysql_query($query,$conn);
$row=mysql_fetch_array($result);
报错是 Warning: mysql_fetch_array() expects parameter 1 to be resource其实我对这个写法中得变量id不甚理解,为什么新定义的一个变量能拿来和数据库表中的id比较呢?
怎样改这个错误呢?
谢谢~~
以下是在网上看到的一种写法include "connect.php";
$id=$_GET["id"];
$query="SELECT * from news Where id=".$id;
$result=mysql_query($query,$conn);
$row=mysql_fetch_array($result);
报错是 Warning: mysql_fetch_array() expects parameter 1 to be resource其实我对这个写法中得变量id不甚理解,为什么新定义的一个变量能拿来和数据库表中的id比较呢?
怎样改这个错误呢?
谢谢~~
估计八成是news表不存在怎的
设程序文件为 test.php,则
http://localhost/test.php?id=1
就能取得 news 表中 id 等于 1 的记录
基本步骤是:
请求:http://xxx.com?id=1$id=$_GET["id"];//这里接受id的值,即1
//查询SELECT * from news Where id=1的记录
$query="SELECT * from news Where id=".$id;
$result=mysql_query($query,$conn);
$row=mysql_fetch_array($result);
呵呵,我有点多此一举了
$_GET 和 $_POST获得的原始数据,不能直接拼接在sql中...必须进行正确性检查,这是常识...
嗯,是的 那些个什么注入就是从 id 开始..养成良好的习惯,也就是那句看了不知道多少回的
Never Trust User Input 永远不要相信用户输入
必须对传递过来的数据进行检测.
输入:SELECT * from news where id=$_GET[id]
弹出:#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 '[id] LIMIT 0, 30' at line 1
<?php$db_host='localhost';
$db_user='root';
$db_pass='';$conn = mysql_connect($db_host,$db_user,$db_pass)or die(mysql_error()."failed to connect to database!");
$db = mysql_select_db('news1',$conn);?>
3、connect.php<?php$db_host='localhost';
$db_user='root';
$db_pass='';$conn = mysql_connect($db_host,$db_user,$db_pass)or die(mysql_error()."failed to connect to database!");
$db = mysql_select_db('news1',$conn);?>
在哪儿加id?
我直接按 http://xxx.com?id=1的输入能看到view的那个内容呐,但是直接打开view.php就不行- -
if(isset($id))
就空白了……
怎么会没有数据呐?我有向数据库里添加东西的说……
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 '' at line 1
希望你先把PHP基础看完再提问