我正在一个项目上,代码中包含以下代码段:
<div id= "searchresults" style="min-height: 10vh; height: auto; background-color:white; display: block;">
<?php
//Makes connection
include 'dxbase.php';
$conn = new mysqli($servername, $username, $password, $dbname);
if(isset($_POST["search"])){
$tempvardf = '%'.$_POST['search'].'%'; #############
//Defines SQL command to bring up data about the products matching the set search
$sql = "SELECT id, name, price, location FROM products WHERE name LIKE ?;"; #'%$_POST[search]%'
//Create a prepared statement
$stmt = mysqli_stmt_init($conn);
//Prepare the prepared statement
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "SQL STATEMENT FAILED... OOF";
} else {
//Bind paramaters to placeholder
mysqli_stmt_bind_param($stmt, "s", $tempvardf);
//Run paramaters inside database
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
while ($row = mysqli_fetch_assoc($result)) {
echo $row['name']. "<br>";
if(isset($row['path'])){
echo "<img src=". $row['path'].">";
} else {
echo "can't access image path";
}
}
echo "And that's it!";
}
} else {
}
?>
</div>
当我搜索时,出现了数据库中产品的名称,但是当我尝试回显图像时,它告诉我它无法访问图像路径。
图像路径在数据库中,如下所示证据:
,但是,我想知道哪里出了问题以及为什么它们没有显示...如此处所示:
尽管我尽了最大的努力和研究时间,但我仍然陷于困境...
答案 0 :(得分:1)
您如何在Select语句中选择图像的路径?您的$ result中没有字段“路径”。