I am trying to display an image from MySQL to an HTML page but all I see is an icon or sometimes some characters. This is what I see. Shows icon which I see
I am using a form to upload the image to the database with some other input fields as well. My form looks like this.
<form method="post" action="http://localhost:63342/sqlvali-master111/publicRoot/sqlvali/index.php?action=lec_hub/pages">
<div class="form-group">
<label for="description" class="control-label">Description:</label>
<input type="text" class="form-control" id="description" name="description">
</div>
<div class="form-group">
<label for="external_link" class="control-label">External Link:</label>
<input type="text" class="form-control" id="external_link" name="external_link">
</div>
<div class="form-group">
<label for="query_structure" class="control-label">Query Structure:</label>
<input type="file" class="form-control" id="query_structure" name="query_structure">
</div>
<div class="form-group">
<label for="feedback" class="control-label">Feedback:</label>
<input type="text" class="form-control" id="feedback" name="feedback">
</div>
<div class="form-group">
<label for="likert" class="control-label">Likert-type Scale:</label>
<input type="text" class="form-control" id="likert" name="likert">
</div>
<div class="form-group">
<label for="query_example" class="control-label">Query Example:</label>
<input type="text" class="form-control" id="query_example" name="query_example">
</div>
<div class="form-group">
<!-- <label for="lec_id_fk" class="control-label">Lecture Foreign Key:</label>-->
<input type="hidden" class="form-control" id="chapter_id_fk" name="chapter_id_fk" value="<?php echo $chapter_id?>">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<input name = "add" type = "submit" id = "add" value = "Add">
</div>
</form>
This is how I add the form data to my database in MySQL
<?php
$con = mysqli_connect("localhost", "root", "", "lectureHub");
if(isset($_POST['add'])) {
$description = $_POST['description'];
$external_link = $_POST['external_link'];
$chapter_id_fk = $_POST['chapter_id_fk'];
$query_structure = $_POST['query_structure'];
$feedback = $_POST['feedback'];
$likert = $_POST['likert'];
$query_example = $_POST['query_example'];
$sql = "INSERT INTO pages (description, external_link, chapter_id_fk, query_structure, feedback, likert, query_example) VALUES('$description','$external_link','$chapter_id_fk', '$query_structure', '$feedback', '$likert', '$query_example')";
// mysqli_select_db("lecturehub");
$retval = mysqli_query($con, $sql);
if(! $retval ) {
die('Could not enter data: ' . mysqli_error());
}
}
This is my current try to display the picture in HTML which renders me only the Icon.
<div class='col-md-8'>
<h3>query Structure</h3>
// <p>$query_structure</p>
<img src='data:image;base64,".base64_encode($row['query_structure'])."' alt='image' style='width: 100px; height: 100px'>
</div>