[英]json not displaying database values
我的頁面已上傳到我的uni服務器,它正在顯示標頭,但不顯示數據庫值,下面是我正在使用的代碼(我通過語法檢查器輸入了代碼,未發現錯誤)
圖書館頁面
<?php
function getAllPictures() {
// include the login credentials
include ("loginasdf.php") ;
// connect to the database to get current state
$conn = mysqli_connect($servername, $username, $password, $database);
if (!$conn) { die("Connection failed: " . mysqli_connect_error()); }
$sql = "select * from Pictures" ;
$result = mysqli_query($conn, $sql);
// convert to JSON
$rows = array();
while($r = mysqli_fetch_assoc($result)) {
$rows[] = $r;
}
return json_encode($rows);
}
?>
loginasdf
<h1>Display All Pictures</h1>
<?php
// define the constants to access the database.
$servername = "***";
$username = "***";
$password = "***";
$dbname = "****";
?>
顯示圖片頁面
<?php
include("library2.php") ;
$picturetxt = getAllPictures() ;
$picturejson = json_decode($picturetxt) ;
// now write out the details
echo "name ".$picturejson -> hname."<br/>" ;
echo "image " .$picturejson -> himage."<br/>" ;
$cl = $picturejson;
for ($i=0 ; $i<sizeof($cl) ; $i++) {
echo "<a href=displaycontact2.php?id=" ;
echo $cl[$i] -> id ;
echo ">" ;
echo $cl[$i] -> hname ;
echo "</a><br/>" ;
}
?>
我不小心在loginasdf頁面上使用了“ dbname”,而在$ conn = mysqli_connect($ servername,$ username,$ password,$ database)上使用了“ database”; 在我的圖書館頁面上
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.