Warning: mysql_query() expects parameter 2 to be resource, boolean given in D:\w

sj211314 2015-04-15 12:39:37
Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in D:\wamp\www\get.php on line 9
Warning: mysql_query() expects parameter 2 to be resource, boolean given in D:\wamp\www\get.php on line 11怎么解决?


代码是这样的!
<?php
session_start();
$_SESSION['times'] = null;
if(!isset($times))
{
$times="0";
}
$link=mysql_connect("localhost","root","123456");
mysql_select_db("chatRoom",$link);
$query="select * from chatroom where times>'$times'";
$result=mysql_query($query,$link);
$megs=array();
echo "<script language='JavaScript'>";
while ($row=mysql_fetch_array($result))
{
if($row["times"] >= $times)

{
$time = $row["times"];
}
echo "top.chatUserName[top.lines.length]=".$row['chatUser']."';\n";
echo "top.showTime[top.lines.length]=".$row['times']."';\n";
echo "top.lines[top.lines.length]=".$row['msg']."';\n";
echo "document.write(top.lines.length);";
}
echo"top.list.location.reload();";
echo "</script>";
?>
<html>
<head>
</head>
<body onLoad="windows.setInterval('location.reload()'4000);">
<!--每4秒刷新一次-->
<h1>
<p align=a"center">
聊天室
</p>
</h1>
</body>
</html>
哪错了?求大神帮助。。。。
...全文
1181 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2015-04-15
  • 打赏
  • 举报
回复
mysql_select_db() expects parameter 2 to be resource, boolean given mysql_select_db() 的第二个参数应该是资源,现在却是逻辑值 表示 $link=mysql_connect("localhost","root","123456"); 数据库连接失败,但为什么没报错呢?
wangsdong1 2015-04-15
  • 打赏
  • 举报
回复
$query="select * from chatroom where times>'$times'"; 去掉这行中的单引号试试
傲雪星枫 2015-04-15
  • 打赏
  • 举报
回复
数据库连接没有成功创建。 $link=mysql_connect("localhost","root","123456") or die(mysql_error()); 加上错误输出看看是什么问题。
ndfee 2015-04-15
  • 打赏
  • 举报
回复
链接失败,返回false,所以$link为false,不是resouce类型

21,881

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧