我有一个图像路径存储在 location upload / imagename.png下的数据库但是我无法在我的页面上显示任何帮助吗?
图像存储在图像文件夹和数据库中,如image / name.png,但是我可以从数据库中获取路径并显示它吗?
我有错误报告,但仍然只是一个空白页面。
<?php include_once('dbconnect.php'); ?>
<?php error_reporting(E_ALL);
ini_set('display_errors', 1); ?>
<?php
if(!empty($_GET['id'])){
//Get image path from database
$result = $con->query("SELECT id, location FROM images WHERE id = {$_GET['id']} AND location = {$_GET['location']}");
if($result->num_rows > 0){
$imgData = $result->fetch_assoc();
echo '<img src='".$row['location']."' />';
}else{
echo 'Image not found...';
}
}
?>
您可以访问 http://yoursite.com/recent.php?id=xxx
等页面 编辑:我试过这个<?php include_once('dbconnect.php'); ?>
<?php error_reporting(E_ALL);
ini_set('display_errors', 1); ?>
<?php
if(!empty($_GET['id'])){
//Get image data from database
$result = $con->query("SELECT id, location FROM images WHERE id = {$_GET['id']} AND location = {$_GET['location']}");
if($result->num_rows > 0){
while($imgData = $result->fetch_assoc()){
echo '<img src="'.$imgData['location'].'"/>';
}
}else{
echo 'Image not found...';
}
}
?>
现在我
Notice: Undefined index: location in /home/vol15_4/epizy.com/epiz_20687250/yourwebprojects.22web.org/htdocs/3/recent.php on line 10
Notice: Trying to get property of non-object in /home/vol15_4/epizy.com/epiz_20687250/yourwebprojects.22web.org/htdocs/3/recent.php on line 12
答案 0 :(得分:0)
您肯定会收到$row
的未定义错误:
if($result->num_rows > 0){
while($imgData = $result->fetch_assoc()){
echo '<img src="'.$imgData['location'].'"/>';
}
}else{
echo 'Image not found...';
}