Search code examples
phphtmlimagesrconerror

OnError img replace issue


Hi guys from reading the answers on this particular page i stumbled upon the onerror flag and thought that would help me out...

but when i merged it with my script it deffo doesnt work for me, im not sure if my php script is getting mixed up here, if someone could advise a novice on what is wrong with my code please.

<td><a href="<?php echo ROOT_URL; ?>images/tbphotos/<?php echo $row['PHOTO3']; ?>"><img style="height: 150px;width: 150px;" src="<?php echo ROOT_URL; ?>images/tbphotos/<?php echo  $row['PHOTO3']; ?>; onerror="this.onerror=null;this.src='<?php echo ROOT_URL; ?>images/thunderball.jpg'"></a></td>

The actual image is in /images/tbphotos the replacement image is /images/thunderball.jpg

TIA Lee


Solution

  • Fixed up a few errors. try the following:

    <td>
      <a href="<?php echo ROOT_URL; ?>images/tbphotos/<?php echo $row['PHOTO3']; ?>"><img style="height: 150px;width: 150px;" src="<?php echo ROOT_URL; ?>images/tbphotos/<?php echo  $row['PHOTO3']; ?>" onerror="this.onerror=null;this.src='<?php echo ROOT_URL; ?>images/thunderball.jpg'"></a>
    </td>