我的页面已经上传到我的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/>" ;
}
?>
答案 0 :(得分:0)
我在loginasdf页面上意外使用“dbname”而在$ conn = mysqli_connect($ servername,$ username,$ password,$ database)中使用“database”;在我的图书馆页面上