【发布时间】:2017-03-23 23:29:44
【问题描述】:
在我的 phpmyadmin 数据库中,我有一个名为 rooms 的表,有 2 列。第 1 列名为 room name 并包含值:bookstore,foodcourt, etc. 第 2 列名为 images 并包含图像的路径:/image/bookstore.jpg, /image/foodcourt.jpg, etc.
form.php 包含用户输入,例如bookstore,foodcourt,etc 提交给image.php
<form name="form" method="POST" action="image.php">
<fieldset>
<p>Where are you trying to go? </p>
<input type="text" name="mapinput" id="mapinput">
<br />
<br />
<input type="submit" name="submit" value="Submit">
</fieldset>
</form>
image.php 应将用户输入与数据库图像路径匹配,并根据用户输入回显图像。
<?php
$conn=mysqli_connect("localhost","xxx","xxx","Capstone");
if (mysqli_connect_errno())
{
echo "Connect failed: " . mysqli_connect_error();
exit();
}
if (isset($_POST['mapinput'])) //mapinput is the user input from the form
{
$map = $_POST['mapinput']; //user input is assigned variable $map
$sql = "SELECT images FROM rooms WHERE room name=$map"; //selecting column images from table rooms where room name = user input ($map)
$result = mysqli_query($conn,$sql);
while($row = mysql_fetch_array($result))
{
echo "<img src = 'images" . $row['images'] . "' />" //images is the column name that holds the image path
}
}
mysqli_close($conn);
?>
通过时,它不会从关联的数据库图像路径中发布任何图像。欢迎任何帮助,谢谢。
【问题讨论】:
-
尝试把完整的网址
<img src = 'http://yoursite.com/images" . $row['images'] . "' /> -
$map 用单引号括起来。 "从房间中选择图像,房间名称='$map'"
-
@meda 图像只是存储在位于 /var/www/html/images 的文件夹中
-
我敢打赌,如果您使用 Ubuntu,这与许可有关。你能告诉我们mysql fetch数组在这里返回什么吗?我的意思是 print_r 到那个