我想從MySql表中檢索數據。我使用的XAMPP,phpMyAdmin的等...我也跟着一步本教程一步:https://www.youtube.com/watch?v=IHdd02IK2Jg未定義的變量:第29行的C: XAMPP htdocs display_prsc.php中的記錄
但我得到這個錯誤:
Notice: Undefined variable: records in C:\XAMPP\htdocs\display_prsc.php on line 29
併發出警告:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, null given in C:\XAMPP\htdocs\display_prsc.php on line 29
它只是顯示列名稱,當我運行它。
<? php
//make connection
mysql_connect('localhost','root','');
//select_db
mysql_select_db('mynewdb');
$sql="SELECT * FROM new";
$records=mysql_query($sql);
?>
<html>
<head>
<title>Program Scores Table</title>
<body>
<table width="600" border="1" cellpadding="1" cellspacing="1">
<tr>
<th>Year</th>
<th>Criteria</th>
<th>Score</th>
<tr>
<?php
while ($new=mysql_fetch_assoc($records)){
echo"<tr>";
echo"<td>".$new['py']."</td>";
echo"<td>".$new['pcrit']."</td>";
echo"<td>".$new['psco']."</td>";
echo"</tr>";
}
?>
</table>
</body>
</head>
</html>
如果在教程的傢伙使用'mysql_ *'我會強烈建議你停止與此教程!並閱讀此:http://php.net/manual/en/book.pdo.php – Rizier123 2015-02-24 09:36:56
這段代碼中有很多錯誤,非常可怕的寫。 – Raptor 2015-02-24 09:47:08
你的html是一個完整的混亂! – Rizier123 2015-02-24 10:19:19