我不斷收到此錯誤: NO數據庫中選擇 有關:沒有數據庫SELECTED-
$result=mysqli_query ('SELECT * FROM admin') or die('SELECT * FROM admin'."<br/> <br/>".mysqli_error());
我相信這是一個問題,將提供幫助,很多新手用戶,如我自己。我已經包含以下的完整代碼:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
<thead>
<tbody>
<?php
$host='localhost';
$user='root';
$pass='';
$db='users';
$con='mysqli_connect($sql_host,$sql_username,$sql_password)';
$con;
if(!$con){
die ('Failed to Connect'.mysqli_error());}
mysqli_select_db('users',$con);
$result=mysqli_query ('SELECT * FROM admin') or die('SELECT * FROM admin'."<br/><br/>".mysqli_error());
while($row=mysqli_fetch_array($result)){
?>
<tr><td><?php echo $row['username'] ?></td></tr>
<tr><td><?php echo $row['password'] ?></td></tr>
<?php
}
?>
</tbody>
</thead>
</body>
</html>
'$ CON = 'mysqli_connect($ sql_host,$ sql_username,$ sql_password)';'應該是'$ CON = mysqli_connect($ sql_host,$ sql_username,$ sql_password,$ db);'並移除'$ con;'和'mysqli_select_db('users',$ con);' – Prix