0

i'm making an admin portal where admin can create users,and when they create user they only add their basic details. so when a user logs in to the system he finds a broken image. to fix that i did some digging and found out about onerror event in img tag. I tried using it,but it is not working.

my code : <img src="images/<?php echo $image;?>" onError="this.onerror=null;this.src='/images/abc.png';"/>

Please help me out here,this is the only task remaining to finish of my 1st project.

ldg
  • 9,112
  • 2
  • 29
  • 44
rohit mishra
  • 37
  • 2
  • 10
  • Theres a php function that checks if a file exists. Than you dont have to deal with js.http://php.net/manual/en/function.file-exists.php – Jonas Wilms Jul 11 '16 at 05:41
  • see: http://stackoverflow.com/questions/92720/jquery-javascript-to-replace-broken-images – ldg Jul 11 '16 at 05:43

1 Answers1

0

As mentioned, you can use PHP to check if the image exists and replace it server-side. To answer your question about the image onerror function, see: jQuery/JavaScript to replace broken images

Community
  • 1
  • 1
ldg
  • 9,112
  • 2
  • 29
  • 44
  • thanks all,my apologies actually i was watching result on a different page i made for test purpose.My mistake just now i figured it out. – rohit mishra Jul 11 '16 at 05:58