Wednesday 21 August 2019

mysql - cant able to fetch what i stored in database with php pdo code

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 "".
"".

"".

"";


$select = $conn->prepare("SELECT * FROM sktable");

$select->execute();
$data=$select->fetchAll(PDO::FETCH_ASSOC);
var_dump($data);
}
}

?>






No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...

"."Image"."

Blog Archive