hey I am new to php and i try to upload image in database and display from database.
Issue:
When i try to fetch i am not be able to fetch the particular image always i got this "array(0) { }" .so please help me clear this code .thanks in advance.
<?php
include'config.php';
if (isset($_POST["ok"])) {
$folder = "img/";
$image = $_FILES['image']['name'];
$path = $folder.$image;
$target_file=$folder.basename($_FILES['image']['name']);
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$allowed = array('jpeg','png','jpg');
$filename = $_FILES['image']['name'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if (!in_array($ext, $allowed)) {
echo "sorry only jpg,jpeg,png and gif files are allowed";
}
else{
move_uploaded_file($_FILES['image']['tmp_name'], $path);
$sth=$conn->prepare("INSERT INTO sktable(image)VALUES('$image');SELECT
image FROM sktable WHERE $image");
$sth->execute();
echo "<table border='2'>".
"<tr>".
"<th>"."Image"."</th>".
"</tr>";
$select = $conn->prepare("SELECT * FROM sktable");
$select->execute();
$data=$select->fetchAll(PDO::FETCH_ASSOC);
var_dump($data);
}
}
?>
<form method="POST" enctype="multipart/form-data">
<input type="file" name="image"/>
<input type="submit" name="ok"/>
</form>
<style type="text/css">
#pimg{
width: 100px;
height: 100px;
}
</style>