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.
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 "".
"".
""."Image"." ".
" ";
$select = $conn->prepare("SELECT * FROM sktable");
$select->execute();
$data=$select->fetchAll(PDO::FETCH_ASSOC);
var_dump($data);
}
}
?>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment