My image in my database is not posting on my site

2019-09-14 17:19发布

问题:

so am created a form that takes two file buttons (for images) one for the thumbnail and the other for the main image and it has successfully taken the files and placed it in the database, it has also gotten their correct directory...but i have a problem...when it time to echo the images they dont show up...some please help me

here is the form and the code(all in the same file called addimage.php):

<?php
include'includes/connect.php';

if($_POST['submit'])
 {
$img="main/";
$img= $img . basename($_FILES['photo1']['name']);

$tmb="thumb/";
$tmb= $tmb . basename($_FILES['photo2']['name']);


$imagename = mysql_real_escape_string($_POST['imagename']);
$content = mysql_real_escape_string($_POST['content']);
$links = mysql_real_escape_string($_POST['links']);
$pic1 = "main/" .(mysql_real_escape_string($_FILES['photo1']['name']));
$pic2 = "thumb/" .(mysql_real_escape_string($_FILES['photo2']['name']));

if(move_uploaded_file($_FILES['photo1']['tmp_name'], $img));{
    if(move_uploaded_file($_FILES['photo2']['tmp_name'], $tmb));{
{

    mysql_query("INSERT INTO `portweb` ( `imagename`, `content`, `links`, `photo1`, `photo2`)  VALUES('$imagename', '$content', '$links', '$pic1', '$pic2')");
    echo "files upload success";
}
}
}
/*else
{
    echo "upload failed";   
}*/

}

?>

<html>
<head>
<title>upload pictures portfolio web</title>
</head>
<body>
<a href="portweb.php">Back</a>
 <br />
 <form action="addportweb.php" method="post" enctype="multipart/form-data">
 <label>Main Image:</label>
 <input type="file" name="photo1" /><br />
<label>Thumb:</label>
<input type="file" name="photo2" /><br />
<label>Name:</label> <input type="text" name="imagename" class="text_input" maxlength="100" /><br />
<label>Description:</label>
<textarea name="content" style="width: 300px; height:80px; padding: 5px; resize:none;" ></textarea>
<br />

<label>Link:</label> <textarea name="links" style="width: 100px; height:50px; padding: 5px; resize:none;" ></textarea><br />
<input type="submit" name="submit" value="upload" /> 
</form>
</body>
</html>

and here is the function to help with the output...and also my problem:

function getportweb() {
     $query = mysql_query("SELECT * FROM portweb") or die(mysql_error());
      while($post = mysql_fetch_assoc($query)){

        echo "<img src =".$post['photo1']."/>";
            echo "<br>";

        echo "<img src =" . $post['photo2'] . "/>";
            echo"<br>";

        echo "<p>" . $post['imagename'] . "</p>";
            echo "<br>";
        echo "<p>" . $post['content'] . "</p>";
        echo "<br>";
        echo "<p>" . $post['links'] . "</p>";
            echo "<br>";

        echo "<a href=\"deleteportweb.php?id=" . $post['id'] . "\">Delete</a>";
        echo "<a href=\"editportweb.php?id=" . $post['id'] . "\">Edit</a>";
         echo "<br>";
         } 

}

i want to believe this is my problem

echo "<img src =".$post['photo1']."/>";
                echo "<br>";

            echo "<img src =" . $post['photo2'] . "/>";
                echo"<br>";

but i got nothing...please someone help

回答1:

Try something like this:

echo'<img src="'.$post['photo1'].'" />';