-5
當我想要獲取我的數據庫信息時,發現此錯誤。此行發現錯誤:警告:mysql_fetch_assoc()期望參數1是資源,布爾在第52行給出的C: xampp htdocs xyz adminpanel.php
while($row = mysql_fetch_assoc($result))
完整的代碼如下所示,我的代碼中是否有任何錯誤?錯誤顯示期望參數1是資源,我需要修復解決方案。
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Admin Panel</title>
<link rel="stylesheet" href="assets/demo.css">
<link rel="stylesheet" href="assets/form-labels-on-top.css">
</head>
<body>
<header>
<h1 align="center"><b>All User Information</b></h1></br>
</header>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "xyz";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
//execute the SQL query and return records
$result = mysql_query("SELECT * FROM user_information");
//if(!$result) die ('Unable to run query:'.mysql_error());
?>
<table border="2" style= "background-color: #84ed86; color: #761a9b; margin: 0 auto;" >
<thead>
<tr>
<th>User ID</th>
<th>User Name</th>
<th>User Country</th>
<th>User Email</th>
<th>User Phone</th>
<td>User Address</td>
<td>User Password</td>
</tr>
</thead>
<tbody>
<?php
while($row = mysql_fetch_assoc($result)){
echo
"<tr>
<td>{$row['user_id']}</td>
<td>{$row['user_name']}</td>
<td>{$row['user_country']}</td>
<td>{$row['user_email']}</td>
<td>{$row['user_phone']}</td>
<td>{$row['user_address']}</td>
<td>{$row['user_password']}</td>
</tr>\n";
}
?>
</tbody>
</table>
</body>
</html>
是的,我已經做到了。感謝您的反饋意見。 – Nayan