Php 数据库中的图像未显示在网页上
所以我有一个我正在创建的博客,但是我在显示从数据库到页面本身的图像时遇到了问题。它只会产生一个破碎的图像。但是,数据确实出现在数据库中。它只是不显示在页面上 下面是image.php代码(用于显示文本和图像):Php 数据库中的图像未显示在网页上,php,html,css,sql,Php,Html,Css,Sql,所以我有一个我正在创建的博客,但是我在显示从数据库到页面本身的图像时遇到了问题。它只会产生一个破碎的图像。但是,数据确实出现在数据库中。它只是不显示在页面上 下面是image.php代码(用于显示文本和图像): 下面是main_menu.php的代码(我希望图像出现在这里) 标题化 “宽度=300高度=300/>; add_post.php <html> <header> </header> <body> <?php //Na
下面是main_menu.php的代码(我希望图像出现在这里)
标题化
“宽度=300高度=300/>;
add_post.php
<html>
<header>
</header>
<body>
<?php
//Name the variables
$host = "localhost";
//Localhost is the name of the computer that USBWebserver has been loaded on
$username = "user";
$password = "pwd";
$database = "blog";
$mysqli=new mysqli($host, $username, $password, $database);
//Get variables from the form
$new_post_title=$_POST["newtitle"];
$new_post_date=$_POST["newdate"];
$new_post_contents=$_POST["newcontents"];
$new_post_rating=$_POST["newrating"];
$photo=addslashes(file_get_contents($_FILES["photo"]["tmp_name"]));
$imagesize=getimagesize($_FILES["photo"]["tmp_name"]);
//mime returns the image time eg. image/jpeg
$imagetype=$imagesize['mime'];
//Enable sql to read quotation marks within sentences
$new_post_title=addslashes($new_post_title);
$new_post_date=addslashes($new_post_date);
$new_post_contents=addslashes($new_post_contents);
$new_post_rating=addslashes($new_post_rating);
//Enter the new information into the posts table
$sql="INSERT INTO posts(postID, title, date, contents, rating, photo, phototype) VALUES (Null, '$new_post_title', '$new_post_date', '$new_post_contents', '$new_post_rating', '$photo', '$imagetype')";
//Run the query
$result=$mysqli->query($sql) or die (mysqli_error($mysqli));
if ($result) {
header ('location:main_menu.php');
}
else {
echo mysql_error();
}
?>
</body>
</html>
您使用的php标记错误
<br><td width="300" align="center"><font color="white">
<?php
echo "<img src="<?php echo $row['photo']; ?>" width=300 height=300/>";
?>
</td>
停止使用mysql-*@nogad,我希望它能这么简单,但这是必需的task@iCoders分析错误:语法错误,意外的“$row”(T_变量),在\main_menu.php的第行中应为“,”或“;”56@Thomas.you在图像中使用了错误的src
<html>
<header>
</header>
<body>
<?php
//Name the variables
$host = "localhost";
//Localhost is the name of the computer that USBWebserver has been loaded on
$username = "user";
$password = "pwd";
$database = "blog";
$mysqli=new mysqli($host, $username, $password, $database);
//Get variables from the form
$new_post_title=$_POST["newtitle"];
$new_post_date=$_POST["newdate"];
$new_post_contents=$_POST["newcontents"];
$new_post_rating=$_POST["newrating"];
$photo=addslashes(file_get_contents($_FILES["photo"]["tmp_name"]));
$imagesize=getimagesize($_FILES["photo"]["tmp_name"]);
//mime returns the image time eg. image/jpeg
$imagetype=$imagesize['mime'];
//Enable sql to read quotation marks within sentences
$new_post_title=addslashes($new_post_title);
$new_post_date=addslashes($new_post_date);
$new_post_contents=addslashes($new_post_contents);
$new_post_rating=addslashes($new_post_rating);
//Enter the new information into the posts table
$sql="INSERT INTO posts(postID, title, date, contents, rating, photo, phototype) VALUES (Null, '$new_post_title', '$new_post_date', '$new_post_contents', '$new_post_rating', '$photo', '$imagetype')";
//Run the query
$result=$mysqli->query($sql) or die (mysqli_error($mysqli));
if ($result) {
header ('location:main_menu.php');
}
else {
echo mysql_error();
}
?>
</body>
</html>
<HTML>
<style>
form {
border-opacity: 1.0 ;
display: incline-block;
text-align: center;
}
input[type=text]:focus, input[type=date]:focus {
width: 50%;
height: 20%;
border: 3px solid #00ffff;
}
body {
text-align: center;
padding-top: 50px;
}
</style>
<HEAD>
</HEAD>
<BODY><font color="white">
<br><br><br><H1 text-align="center">Add a New Post</H1>
<?php
//Connect To Header Page
include "header1.php";
//Connect To Database
include "dbconnect.php";
?>
<br>
<br>
<!-- <HR> Tag inserts a horizonal line across the page (horizontal rule)-->
<!-- <Form> Tag indicates that a form will be created -->
<!-- action indicates the file used to process the input when the submit button is pressed-->
<form enctype= "multipart/form-data" action="add_post.php" method = "POST">
Title: <br>
<!-- <input type> Tag indicates the type of input expected eg. text. Name = indicates the name given to the input-->
<input type="text" name="newtitle"><br>
Date: <br>
<input type="date" name="newdate"><br>
Contents: <br>
<input type="text" name="newcontents"><br>
Rating: <br>
<input type="text" name="newrating"><br>
Please Browse to where the photo is located:<br>
<input type = file name = "photo"><br>
<br>
<!-- Value indicates the text to be displayed. In this case, displayed on the button -->
<input type ="submit" value="Submit">
</form>
</BODY>
</HTML>
<br><td width="300" align="center"><font color="white">
<?php
echo "<img src="<?php echo $row['photo']; ?>" width=300 height=300/>";
?>
</td>
<br><td width="300" align="center"><font color="white">
<img src="<?php echo $row['photo']; ?>" width=300 height=300/>
</td>