首页上一页 1 下一页尾页 2 条记录 1/1页
急急急!!!关于操作数据库的一个问题
发表在PHP图书答疑
2009-07-01
是否精华
是
否
版块置顶:
是
否
[font size=4]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<script language="javascript">
function check(form){
if(form.keywords.value==""){
alert('请输入查询关键字!');form.keywords.focus();return false;
}
form.submit();
}
</script>
<table width="100%" border="1">
<tr>
<td><form id="form1" name="form1" method="post" action="">
查询关键字:
<label>
<input name="keywords" type="text" id="keywords" />
</label>
<label>
<input type="submit" name="Submit" value="搜索" onclick="return check(form1);" />
</label>
</form>
</td>
</tr>
</table>
<?php
if($_POST[Submit]=="搜索"){
$keywords=$_POST[keywords];
$conn=mysql_connect("localhost","root","root") or die("服务器连接失败!".mysql_error());
mysql_select_db("db_study",$conn) or die("数据库连接失败!".mysql_error);
mysql_query("set names gb2312");
$sql=mysql_query("select * from tb_affiche where title like '%".trim($keywords)."%' or content like '%".$keywords."%'");
$row=mysql_fetch_row($sql);
if($row==false){
echo "<script language=javascript>alert('没有找到相关记录!');history.back();</script>";
}
}else{
$sql=mysql_query("select * from tb_affiche");
$row=mysql_fetch_row($sql);
}
?>
<hr />
<table width="100%" border="1">
<tr>
<td width="23%">公告标题</td>
<td width="77%">公告内容</td>
</tr>
<?php
do {
?>
<tr>
<td><?php echo $row[1]; ?></td>
<td><?php echo $row[2]; ?></td>
</tr>
<?php
} while($row=mysql_fetch_row($sql));
mysql_free_result($sql);
mysql_close($conn);
?>
</table>
<p> </p>
</body>
</html>
[/font]
错误提示:
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in F:\Appserv\www\www\charpter18\18.8.php on line 44
--------------------------------------------------------------------------------
公告标题 公告内容
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in F:\Appserv\www\www\charpter18\18.8.php on line 61
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in F:\Appserv\www\www\charpter18\18.8.php on line 62
Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in F:\Appserv\www\www\charpter18\18.8.php on line 63
但是输入搜索关键字后将会有结果出来也不会显示任何错误。请哪位高手教一下啊 感激感激。。。。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<script language="javascript">
function check(form){
if(form.keywords.value==""){
alert('请输入查询关键字!');form.keywords.focus();return false;
}
form.submit();
}
</script>
<table width="100%" border="1">
<tr>
<td><form id="form1" name="form1" method="post" action="">
查询关键字:
<label>
<input name="keywords" type="text" id="keywords" />
</label>
<label>
<input type="submit" name="Submit" value="搜索" onclick="return check(form1);" />
</label>
</form>
</td>
</tr>
</table>
<?php
if($_POST[Submit]=="搜索"){
$keywords=$_POST[keywords];
$conn=mysql_connect("localhost","root","root") or die("服务器连接失败!".mysql_error());
mysql_select_db("db_study",$conn) or die("数据库连接失败!".mysql_error);
mysql_query("set names gb2312");
$sql=mysql_query("select * from tb_affiche where title like '%".trim($keywords)."%' or content like '%".$keywords."%'");
$row=mysql_fetch_row($sql);
if($row==false){
echo "<script language=javascript>alert('没有找到相关记录!');history.back();</script>";
}
}else{
$sql=mysql_query("select * from tb_affiche");
$row=mysql_fetch_row($sql);
}
?>
<hr />
<table width="100%" border="1">
<tr>
<td width="23%">公告标题</td>
<td width="77%">公告内容</td>
</tr>
<?php
do {
?>
<tr>
<td><?php echo $row[1]; ?></td>
<td><?php echo $row[2]; ?></td>
</tr>
<?php
} while($row=mysql_fetch_row($sql));
mysql_free_result($sql);
mysql_close($conn);
?>
</table>
<p> </p>
</body>
</html>
[/font]
错误提示:
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in F:\Appserv\www\www\charpter18\18.8.php on line 44
--------------------------------------------------------------------------------
公告标题 公告内容
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in F:\Appserv\www\www\charpter18\18.8.php on line 61
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in F:\Appserv\www\www\charpter18\18.8.php on line 62
Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in F:\Appserv\www\www\charpter18\18.8.php on line 63
但是输入搜索关键字后将会有结果出来也不会显示任何错误。请哪位高手教一下啊 感激感激。。。。