这个问题在这里已经有了答案:
mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc... expects parameter 1 to be resource
(31 个回答)
6年前关闭。
到目前为止,我的代码似乎与我收到以下错误的一行不同:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Website\Search.php on line 37
第 37 行如下:
while($name=mysql_fetch_assoc($records))
其余代码:
HEAD> <TITLE> Search </TITLE> </HEAD>
<BODY>
<h1>Search for your favourite movies here</h1>
<b>`enter code here`
<p> Here you can search through our exciting selection of existing and upcoming movies </p>
<p> You can search our website by choosing from one of the drop down lists below depending on what you
know about the movie </p>
</b>
<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('database');
$sql="SELECT * FROM names";
$records=mysql_query($sql);
mysql_connect();
?>
<html>
<body>
<table width="600" border="1" cellpadding="1" cellspacing="1">
</table>
<tr>
<th>fname</th>
<th>sname</th>
<th>age</th>
<tr>
<?php
while($name=mysql_fetch_assoc($records))
{
echo "<tr>";
echo "<td>.$name.['fname'].</td>";
echo "<td>.$name.['sname'].</td>";
echo "<td>.$name.['age'].</td>";
echo "</tr>";
}
?>
</BODY>
</HTML>
我正在尝试从数据库中复制信息并将其显示在我的网页上。任何帮助将不胜感激。
最佳答案
你在做mysql_connect()
两次 - 第二次没有参数。
因此,当您执行 mysql_fetch_assoc()
时,您没有有效的资源。 .
关于从数据库获取信息时出现 PHP 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29920563/