Default image if no record with image path on database

how to keep image path name if no new image been uploaded?
show default image when image not found
how to set default image in php
display image in edit form to update it in php
how to update image in php with demo
show default image when image not found angular 6
show default image if image not found php
broken image handling

I want to show a default image if there isn't any record on the table of images. I am using this one, but it shows nothing when the db's table is empty.

<img class="image--cover" id="blah" src="<?php echo $row2['img_local']; ?>" alt="Avatar" title="DEFINIDA" onerror="this.onerror=null;this.src='1.png';">

Actually, it doesn't even shows some broken image icon, not even the allocated space for this element. Any thoughts?

Edit: this is the "upload.php" code that i am using to upload the images

    $newFilename=$fileinfo['filename'] ."_". time() . "." . $fileinfo['extension'];
    move_uploaded_file($_FILES["image"]["tmp_name"],"images/perfis/" . $newFilename);
    $location="images/perfis/" . $newFilename;

$todas_fotos = mysqli_query($conexao, "select * FROM esc_usuarios_fotos WHERE img_usu_codigo = '" . $_SESSION['codigo'] . "'");

if( mysqli_num_rows($todas_fotos) > 0) {
        //if(unlink($path)) echo "Deleted file ";
        mysqli_query($conexao,"UPDATE esc_usuarios_fotos SET img_local = '$location' WHERE img_usu_codigo = '" . $_SESSION['codigo'] . "'");
        mysqli_query($conexao,"insert into esc_usuarios_fotos (img_local, img_usu_codigo) values ('$location', '" . $_SESSION['codigo'] . "')");


you can try

<img class="image--cover" id="blah" src="<?php if(!empty($row2['img_local'])){ echo $row2['img_local'];}else{ echo '1.png';} ?>" alt="Avatar" title="DEFINIDA" >

Also check path of 1.png.. Like images/1.png or img/1.png etc..

php - Default image if no record with image path on database, I want to show a default image if there isn't any record on the table of images. I am using this one, but it shows nothing when the db's table is  Hi.. I want to store a default image in binary format,into database table when no image file is uploaded from fileupload control in my web page.i don't want to insert null values in "image" field of image table I have searched on google but couldn't find solution.

we can try set by-default value to database column img_local (Ex. default.png) , so if user not change image or there is no insert image in database it's remain default.png ,if user change it become user.png , if user remove image it's again update to default.png

Default image if no record with image path on database , I want to show a default image if there isn't any record on the table of images. I am using this one, but it shows nothing when the db's table is empty. Actually  Introduction: In this article I will explain how to insert images into our project folder and display the images from folder in gridview based on images path in database using Description: In my previous article I explained clearly how to insert images into database and display images from database into gridview.

Please try the below logic:

$row2['img_local'] = 'DB_data_folder_Path_to_image_with_image_name.extension';
// You do not have to use above line.

if ((!empty($row2['img_local'])) && (file_exists($row2['img_local']))) {
    echo '<img class="image--cover" id="blah" src="'.$row2['img_local'].'" alt="Avatar" title="DEFINIDA" onerror="this.onerror=null;this.src=1.png;">';
} else {
    echo 'Show a default image.'; // <img src="path_to_default_image" alt="Default_image"/>

How to Keep image path name if no new image been uploaded , which update and upload image to the folder and sends path to the database set if no new image upload keep old image path or dnt change the the row on  Every tutorial I read suggested it’s best to store images in a folder and store the path into a database as opposed to storing images into a database. I want to allow users to store data and an image then retrieve and display the data and image, I know how to display the data but not the uploaded image.

My friend,

If you get this from HTML perspective... and put that image in one DIV, your [onerror="";] could work better.

like this example:

<div id="myContainerImg">
    <img class="image--cover" id="blah" src="<?php echo $row2['img_local']; ?>" alt="Avatar" title="DEFINIDA" onerror="putNoImage();">

<script type="text/javascript">
  function putNoImage(){
    document.getElementById('myContainerImg').innerHTML = 'no image here, or put your own img...';

And, you can see it running here on CodePen.

How to handle loading of images that may not exist?, If an image does not exist, then it should be removed from the database. An image URL that is incorrect or points to an image that no longer exists, is most likely a data issue. If yes, then the image stays in your database, else you can discard Specifying the default image to be displayed in the URL --> Insert image into folder and inset image path into database and display image in view from image folder based on path given (stored) in database. Here, we will learn how to save an image in the database and to retrieve it into MVC 5 Views. The images stored as Binary data will be fetched as BYTE Array and then, the BYTE

Attach files and graphics to the records in your database, For example, if you store JPEG image files in an Access database, every computer By default, each field in a relational database contains only one piece of data. However, attachments do not break any design rules, because as you attach files to a The folder path appears in the Temporary Internet Files folder section. My imageview downloads images for students but when the student has no image I am trying to display a default image. I have tried two things I thought should work, set a default image, or the code below.

File Manager, We recommend using the default base URL variable {base_url} defined in URL and Path Settings in The full server path (not a URL) to the upload folder for this destination. Images only: The system will only allow image files of the type GIF, JPG, JPEG, or PNG. If there is no record in the database, one will be added. Store file paths and names of images in a table. Display images by using an image control. Hide the image control if no image is available. Provide feedback on the display status of the image. This article also contains sample Visual Basic script that you can use to display the images in a data access page.

imagejpeg - Manual, The path or an open stream resource (which is automatically being closed after this function If not set or NULL , the raw image stream will be outputted directly. The default (-1) uses the default IJG quality value (about 75). I was pulling a blob encoded base 64 data from mysql database and trying to render it on a page Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more php setting default image if there is no image uploaded to database

  • did you check your style.? style may affect the element.!
  • Can you show what's echoed in <?php echo $row2['img_local']; ?>
  • i have updated the details
  • Still, nothing is loaded
  • do you check path of 1.png ? is it in root folder or in any subfolder ? also is it class="image--cover" or class="image-cover" ? if 1.png is in images folder, then it should be src="<?php if(!empty($row2['img_local'])){ echo $row2['img_local'];}else{ echo 'images/1.png';} ?>"
  • the path is correct, but i got no changes at all trying different paths
  • Nothing, it's so weird, looks like there is no difference between a wrong and correct path
  • Newbie here, how to go?
  • ALTER TABLE table_name ALTER COLUMN column_name SET DEFAULT 'images/default.png'. then add default.png in your images folder
  • But if the user removes the image, nothing is shown, cause in your code, there must be at least one record to show default.png, waht I want is to show a image if there is nothing on database
  • when user click 'remove image' button , dont delete it , instead of delete query execute update query , and set again to 'images/default.png' as a value to column
  • Nothing yet, i'm losting hope
  • You have set "images/perfis/" . $newFilename in DB. So on trying to display it, you have to specify the full path. Can you add the path on which you are seeing this page in browser or the folder structure