【发布时间】:2016-06-24 13:10:18
【问题描述】:
我创建了一个包含 id、描述、关键字、年份和位置的数据库。我正在创建一个页面,该页面将填充所有上传到我的数据库的页面。需要明确的是,我已将上传的图像保存到服务器上的文件夹中,而不是我的数据库中。
我可以设法获得一个包含数据库字段的表格,但现在我正试图将与图像 ID 对应的图像放入表格中。
我相信我需要做类似的事情
$query = "SELECT * FROM insert image path here
我尝试了不同的方法,但没有任何效果。
附:我正在使用 MAMP,目前实际上并未将其上传到服务器。
下面是我的代码:
<html>
<body>
<?php
error_reporting(-1);
// connection
// TODO:secure connection details
$servername = "localhost";
$username = "name";
$password = "password";
$dbname = "archive";
$dirname = "uploads/";
// Create db connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// stop if failed
if (mysqli_connect_errno()) {
die("Connection failed: " .
mysqli_connect_error() .
" " . mysqli_connect_errno());
}
// I think I need to call the img before the data
$query = "SELECT * FROM $target_file = "uploads/img_".$id.".jpg";"
// TODO: fix SQL injection
$query = "SELECT * FROM photo_data"; // give me everything from photodata table ordered desc
$result = mysqli_query($conn, $query);
if (!$result){
die("Database query failed." . mysqli_error($conn));
} else {
echo "<table border='1'>";
echo "<tr><th>id</th><th>uniqueid</th><th>description</th><th>keywords</th><th>year</th><th>location</th><th>target file</th></tr>";
//building row by adding values
while($row = mysqli_fetch_row($result)){
echo "<tr>";
//building columns
foreach ($row as $key => $value) {
echo "<td>",$value,"</td>";
}
// I think I need to add my images in the section above
echo "</tr>";
}
echo "</table>";
}
mysqli_close($conn);
?>
</body>
</html>
【问题讨论】:
-
我看到的唯一问题是没有输出用于显示图像的 HTML 对吗?
-
@Dagon 这是您看到的唯一问题?我在一行中至少看到 3 个问题:
$query = "SELECT * FROM $target_file = "uploads/img_".$id.".jpg";"