在我的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);
?>
执行时,它不会从关联的数据库图像路径发布任何图像。欢迎任何帮助,谢谢。
答案 0 :(得分:0)
这似乎是一个路径问题。最好的想法是打开一个萤火虫。尝试检查破损的图像。您将能够了解路径出了什么问题。一旦遇到问题,请在 $ row ['images'] 之前添加正确的网址。