PHP MySQL显示数据库中的图像
嗨,我有表格,使新的信息和图像文章。我成功地将所有信息和图像保存到数据库(我猜)。当我想显示信息和图像时,只有信息起作用。 请看图片 有什么帮助吗?非常感谢 插入_post.phpPHP MySQL显示数据库中的图像,php,html,mysql,Php,Html,Mysql,嗨,我有表格,使新的信息和图像文章。我成功地将所有信息和图像保存到数据库(我猜)。当我想显示信息和图像时,只有信息起作用。 请看图片 有什么帮助吗?非常感谢 插入_post.php <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <me
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>APK Market</title>
<link rel="stylesheet" type="text/css" href="../style/style.css">
<link href="../bootstrap/css/bootstrap.css" rel="stylesheet" media="screen">
<script src="../bootstrap/js/bootstrap.min.js"></script>
<script src="../bootstrap/js/bootstrap.js"></script>
</head>
<body>
<form method="post" action="insert_post.php" enctype="multipart/form-data">
<div class="new_post">
<div class="headtitle">Insert new post</div>
<div class="new_title">
<p>New title</p>
<input type="text" name="title">
</div>
<div class="new_author">
<p>Author</p>
<input type="text" name="author">
</div>
<div class="new_keywords">
<p>Keywords</p>
<input type="text" name="keywords">
</div>
<div class="new_image">
<p>Image</p>
<input type="file" name="image">
</div>
<div class="new_content">
<textarea name="content" cols="20" rows="8"></textarea>
</div>
<div class="submit">
<input type="submit" name="submit" value="OK">
</div>
</div>
</form>
<script src="https://code.jquery.com/jquery.js"></script>
<script src="../bootstrap/js/bootstrap.js"></script>
</body>
</html>
<?php
include("../includes/connect.php");
if(isset($_POST['submit']))
{
$games_date = date('y-m-d-h');
$games_title = $_POST['title'];
$games_author = $_POST['author'];
$games_keywords = $_POST['keywords'];
$games_image = $_FILES['image']['name'];
$games_tmp = $_FILES['image']['tmp_name'];
$games_content = $_POST['content'];
if($games_title=="" or $games_author=="" or $games_keywords==""
or $games_content=="")
{
echo"<script>alert('any field is empty')</script>";
exit();
}
else
move_uploaded_file($games_tmp,"../uploaded_images/$games_image");
$insert_query= "insert into games(games_title,games_date,games_author,games_image,
games_keywords,games_content)
values ('$games_title','$games_date','$games_author','$games_image',
'$games_keywords','$games_cont ent')";
}
if(mysql_query($insert_query))
{
echo "<center><h1>Post published seccesfuly!</h1></center>";
}
?>
display page:
<div class="content">
<?php
include('connect.php');
$select_posts = "select * from games";
$run_posts = mysql_query($select_posts);
while($row=mysql_fetch_array($run_posts))
{
echo '<p class="games_title_result">' .$games_title = $row['games_title'];
echo '<p class="games_image_result"><img src="<?php echo $row["games_image"];?>';
echo '<p class="games_content_result">' .$games_content = $row['games_content'];
echo '<p class="games_date_result">' .$games_date = $row['games_date'];
echo '<p class="games_author_result">' .$games_author = $row['games_author'];
}
?>
</div>
APK市场
插入新员额
新标题
作者
关键词
形象
您的图像标记未正确关闭,图像路径不完整。您只指定了文件名。我不确定你的目录结构
echo '<p class="games_image_result"><img src="uploaded_images/<?php echo $row["games_image"];?>" />';
echo'“/>”;
以下是我的答案:
echo '<p class="games_image_result"><img src="uploaded_images/'.$row["games_image"].'" />';
echo';
您遇到了一个语法错误,在php中包含了一个
,并且在回音中出现了这个错误
所以当你看你的img的src时,它会有这些
另外,您忘记关闭img标记和其他p标记。使用php显示数据库中的图像
# SQL Statement
$sql = "SELECT `idimage` FROM `yourTableName` WHERE id=" . mysqli_real_escape_string($_GET['id']) . ";";
$result = mysqli_query("$sql") or die("Invalid query: " . mysqli_error());
# Set header
header("Content-type: image/your image name which type of your image");
echo mysqli_result($result, 0);
}
else
echo 'Please check the ID!';
?>
我希望它能对你有所帮助你能给我们一个例子games\u image
你数据库中的值吗?同时告诉我们你的文件夹图像在哪里。目录。我不知道我是否理解。games\u image value from database?目录是:../uploaded\u images/第一次我有这个:echo'';再次阅读我的文章,我编辑它时,你可能遗漏了一些内容。如果我想让这张图片的宽度为:x px,高度为:x px,我必须把它放在哪里?
或通过CSS。或者内联风格——别忘了把我的帖子选为最佳答案。勾选复选标记。:)我赞成你那美妙的、最好的、不起眼的回答:)