This question already has an answer here:
So far my code seems to work apart from one line where i get the following error:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Website\Search.php on line 37
Line 37 is as follows:
while($name=mysql_fetch_assoc($records))
The rest of the code:
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>
I am attempting to copy information from a database and display it on my webpage. Any help will be appreciated.
</div>
You are doing mysql_connect()
twice - the second time without parameters. So you don't have a valid resource when you do the mysql_fetch_assoc()
.