菜鸟求助

ziwuxian666 2010-08-12 12:59:05
刚接触PHP,学习过程中出现了点小问题,不知道哪里错了,望各位帮忙
浏览器显示:
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\a\show.php on line 14

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\a\show.php on line 20

网页源代码:
<?
//----------基本设定-------
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "000";
$mysql_database = "wl";
//------------------------

//准备好您的SQL语法(查询)
$sql = "SELECT * FROM 'gbook'";

$conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password);
$result=mysql_db_query($mysql_database,$sql,$conn);
while($row=mysql_fetch_row($result))
{
print_r($row);


}
mysql_free_result($result);


?>
...全文
52 点赞 收藏 11
写回复
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
phper_cd 2010-08-12
键盘上英文输入法下1旁边的那个键就能打出`
回复
phper_cd 2010-08-12
`这个可不是引号哦
回复
shoulder2010 2010-08-12
[Quote=引用 3 楼 xuzuning 的回复:]


$sql = "SELECT * FROM `gbook`";
不是
$sql = "SELECT * FROM 'gbook'";
[/Quote]
楼上正解!
回复
yuexiangyun 2010-08-12
$sql = "SELECT * FROM gbook";
//设置连接DB
$conn=mysql_connect($servername,$username,$password);
//选择DB资料库
mysql_select_db($dbname);
//执行sql
$result = mysql_query($sql,$conn);
//取出资料
while($rows = mysql_fetch_row($result)){
//echo
}
回复
xiaocai520 2010-08-12
第一个连接mysql mysql_connect
第二个你要知道你操作的数据库 mysql_select_db
第三个执行你的sql语句 mysql_query
回复
Dleno 2010-08-12
你最好还是先 看下文档,至少要知道最基本的用法!
回复
Dleno 2010-08-12

<?
//----------基本设定-------
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "000";
$mysql_database = "wl";
//------------------------

//准备好您的SQL语法(查询)
$sql = "SELECT * FROM `gbook`";

$conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password) or die("Error connect:".mysql_error());
mysql_select_db($mysql_database,$conn) or die("Error select_db:".mysql_error());
$result=mysql_query($sql,$conn) or die("Error query:".mysql_error());
while($row=mysql_fetch_row($result))
{
print_r($row);


}
mysql_free_result($result);


?>
回复
caizhuguanguan 2010-08-12
[Quote=引用 3 楼 xuzuning 的回复:]

$sql = "SELECT * FROM `gbook`";
不是
$sql = "SELECT * FROM 'gbook'";
[/Quote]
不加引号 也可
回复
xuzuning 2010-08-12

$sql = "SELECT * FROM `gbook`";
不是
$sql = "SELECT * FROM 'gbook'";
回复
blue44sky 2010-08-12
$conn=mysql_connect($servername,$username,$password);
mysql_select_db($dbname,$conn);
mysql_query();
msyql_fetch_row;
回复
blue44sky 2010-08-12
$result=mysql_db_query($mysql_database,$sql,$conn);
直接用mysql_query()试下.
应该是你的查询不成功
回复
发动态
发帖子
基础编程
创建于2007-09-28

2.1w+

社区成员

从PHP安装配置,PHP入门,PHP基础到PHP应用
申请成为版主
社区公告
暂无公告