0

The HTML upload form:

<form action="InformationData.php" method="post" enctype="multipart/form-data">
    <label >Barangay Certification</label>
    <input name="BarangayCertification" type="file" id="exampleInputFile1">
    <button type="Submit" name="Submit" value="Upload">Submit</button>
</form>

The InformationData.php:

<?php 
$conn = mysqli_connect("localhost", "root", "", "registration");

if($_POST['BarangayCertification']){
    $BarangayCertification =   $_POST['BarangayCertification'];
} else {
    $BarangayCertification =  "";
}

$sql = "INSERT INTO stakeholdersform (BarangayCertification) VALUES ($BarangayCertification);
?>

Code to show the image:

<?php
$conn = mysqli_connect("localhost", "root", "", "registration");
$informations = "SELECT * FROM stakeholderinformations";
$result = $conn->query($informations);

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        $BarangayCertification = $row['BarangayCertification']; 
        echo $BarangayCertification;
    }
}
?>

I tried to echo it but nothing happens, but I can see the image in the database.

Sebastian Brosch
  • 42,106
  • 15
  • 72
  • 87

2 Answers2

0

From PHP documentation

echo — Output one or more strings

So, no, you can not echo image. What you could do is

echo '<img src="data:image/jpeg;base64,' . $BarangayCertification . '">'

Although there's an upper limit about the size of $BarangayCertification and I do not recommend storing image in your database.

theminer3746
  • 888
  • 13
  • 32
0

If connection to databases is set correctly.this below code work.But at first you must create a directory upload in the root

form

<form action="InformationData.php" method="post" enctype="multipart/form-data">
    <label >Barangay Certification</label>
    <input name="BarangayCertification" type="file" id="exampleInputFile1">
    <button type="Submit" name="Submit" value="Upload">Submit</button>
</form>

The InformationData.php:

<?php 
$conn = mysqli_connect("localhost", "root", "", "registration");

if (isset($_POST("Submit"))){
if($_POST['BarangayCertification']){
   // $BarangayCertification =   $_POST['BarangayCertification'];
            if (file_exists("upload/" . $_FILES["BarangayCertification"]["name"])) {
            echo $_FILES["BarangayCertification"]["name"] . " <b>already exists.</b> ";
            } else {
                 ///creat upload in root 
            move_uploaded_file($_FILES["BarangayCertification"]["tmp_name"], "upload/" . $_FILES["BarangayCertification"]["name"]);
            $BarangayCertification = "//".$_SERVER['HTTP_HOST'].'//'. "upload/" . $_FILES["file"]["name"];

            }
} else {
    $BarangayCertification =  "";
}
}
$sql = "INSERT INTO stakeholdersform (BarangayCertification) VALUES ($BarangayCertification)";
?>

Code to show the image:

<?php
$conn = mysqli_connect("localhost", "root", "", "registration");
$informations = "SELECT * FROM stakeholderinformations";
$result = $conn->query($informations);

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        $BarangayCertification = $row['BarangayCertification']; 
        echo "<img src=".$BarangayCertification.">";
    }
}
?>
pedram shabani
  • 1,654
  • 2
  • 20
  • 30