0
到目前爲止,我的代碼似乎從一條線在那裏我碰到下面的錯誤除了工作:PHP錯誤從數據庫中取資料時
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>
我試圖從數據庫中複製信息並將其顯示在我的網頁上。任何幫助將不勝感激。
remove mysql_connect();在查詢 – Saty
之後試着用'或者死(mysql_error())'看看是否有錯誤 –
請停止使用'mysql_ *'函數](http://stackoverflow.com/questions/12859942/why-shouldnt-i -use MySQL的函數式的PHP)。他們不再被維護,並[正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。瞭解[準備的陳述](http://en.wikipedia.org/wiki/Prepared_statement),並使用[PDO](http://jayblanchard.net/demystifying_php_pdo.html)。 –