我正在嘗試使用PHP顯示我的表,t2d_10和數據庫chr10。我的表有5列,分別是rs1,rs2,rs3,rs4,rs5。這是我的代碼:顯示數據庫中的表時出錯
<?php
// set database server access variables:
$host = "localhost";
$user = "root";
$pass = "";
$db = "chr10";
// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db, $connection) or die ("Unable to select database!");
// create query
$query = "SELECT * FROM t2d_10";
// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
// see if any rows were returned
if (mysql_num_rows($result) > 0) {
// yes
// print them one after another
echo "<table cellpadding=10 border=1>";
while($row = mysql_fetch_row($result)) {
echo "<tr>";
echo "<td>".$row['rs1']."</td>";
echo "<td>".$row['rs2']."</td>";
echo "<td>".$row['rs3']."</td>";
echo "<td>".$row['rs4']."</td>";
echo "<td>".$row['rs5']."</td>";
echo "</tr>";
}
echo "</table>";
}
else {
// no
// print status message
echo "No rows found!";
}
// free result set memory
mysql_free_result($result);
// close connection
mysql_close($connection);
?>
錯誤:
Notice: Undefined index: rs1 in C:\wamp\www\ch\run_db.php on line 28
Notice: Undefined index: rs2 in C:\wamp\www\ch\run_db.php on line 29
Notice: Undefined index: rs3 in C:\wamp\www\ch\run_db.php on line 30
Notice: Undefined index: rs4 in C:\wamp\www\ch\run_db.php on line 31
Notice: Undefined index: rs5 in C:\wamp\www\ch\run_db.php on line 32
我是相當新的這個PHP。任何人都可以幫助我嗎?提前致謝。
'mysql_select_db($連接)'一兩件事。 –
@ Fred-ii-:不,那會是錯誤的。 OP的是正確的。 http://www.php.net/manual/en/function.mysql-select-db.php –
@LightnessRacesinOrbit Duh,對不起。我的錯誤哈哈我的意思是'mysql_select_db($ db,$連接)' –