html - How to hide broken image icon in PHP? -
insert picture in database code: if (!isset($_files['gambarid']['tmp_name'])) { echo ""; }else{ $rand5=rand(); $image_name5= addslashes($_files['gambarid']['name']); $fileext5=explode('.',$image_name5); $image_new5=$rand5; move_uploaded_file($_files["gambarid"]["tmp_name"],"images/gambarid/" . $image_new5 . $image_name5); $gambarid="images/gambarid/" . $image_new5 . $image_name5; } if (!isset($_files['icdepan']['tmp_name'])) { echo ""; }else{ $rand=rand(); $image_name= addslashes($_files['icdepan']['name']); $fileext=explode('.',$image_name); $image_new=$rand; move_uploaded_file($_files["icdepan"]["tmp_name"],"images/gambarkondisi/" . $image_new . $image_name); $icdepan="images/gambarkondisi/" . $image_new . $image_name; } if (!isset($_files['icbelakang']['tmp_name'])) { echo ""; }else{ $rand2=rand(); $image_name2= addslashes($_files['icbelakang']['name']); $fileext2=explode('.',$image_name2); $image_new2=$rand2; move_uploaded_file($_files["icbelakang"]["tmp_name"],"images/gambarkondisi/" . $image_new2 . $image_name2); $icbelakang="images/gambarkondisi/" . $image_new2 . $image_name2; } if (!isset($_files['icatas']['tmp_name'])) { echo ""; }else{ $rand3=rand(); $image_name3= addslashes($_files['icatas']['name']); $fileext3=explode('.',$image_name3); $image_new3=$rand3; move_uploaded_file($_files["icatas"]["tmp_name"],"images/gambarkondisi/" . $image_new3 . $image_name3); $icatas="images/gambarkondisi/" . $image_new3 . $image_name3; } if (!isset($_files['icbawah']['tmp_name'])) { echo ""; }else{ $rand4=rand(); $image_name4= addslashes($_files['icbawah']['name']); $fileext4=explode('.',$image_name4); $image_new4=$rand4; move_uploaded_file($_files["icbawah"]["tmp_name"],"images/gambarkondisi/" . $image_new4 . $image_name4); $icbawah="images/gambarkondisi/" . $image_new4 . $image_name4; } if (!isset($_files['closeup1']['tmp_name'])) { echo ""; }else{ $rand6=rand(); $image_name6= addslashes($_files['closeup1']['name']); $fileext6=explode('.',$image_name6); $image_new6=$rand6; move_uploaded_file($_files["closeup1"]["tmp_name"],"images/gambarkondisi/" . $image_new6 . $image_name6); $closeup1="images/gambarkondisi/" . $image_new6 . $image_name6; } if (!isset($_files['closeup2']['tmp_name'])) { echo ""; }else{ $rand7=rand(); $image_name7= addslashes($_files['closeup2']['name']); $fileext7=explode('.',$image_name7); $image_new7=$rand7; move_uploaded_file($_files["closeup2"]["tmp_name"],"images/gambarkondisi/" . $image_new7 . $image_name7); $closeup2="images/gambarkondisi/" . $image_new7 . $image_name7; }
<!doctype html> <html> <head> <link rel="stylesheet" href="style2.css" /> </head> <body> <div class="container"> <div class="main"> </br></br> <form action="" method="post"> <a href="#" onclick="window.print()" class="btn btn-info"><i class="fa fa-print"></i> print list</a> <table width="100%" border="0"> <tr> <td width="20%" rowspan="2" align="left"><img src="images/logojmm.png" alt="logojmm" width="150" height="160" ></td> <td width="80%" colspan="2" align="right"><strong> ref. no: </strong></td> </tr> <tr> <td colspan="2"><strong><font size="6"> bahagian pengurusan konservasi</font> <br><br><font size="4"> condition report</strong><br> penilaian kondisi</strong></font></td> </tr> </table> <!-- <a data-toggle="modal" href="#student_delete" id="delete" class="btn btn-danger" name=""><i class="fa fa-trash-o"></i> delete</a> --> <hr> <table width="100%" cellpadding="3" cellspacing="1" border=1"> <tbody> <?php // connect database server mysql_connect("localhost", "root", "") or die (mysql_error ()); // select database mysql_select_db("dbinve") or die(mysql_error()); // data database depending on value of id in url $strsql = "select * konservasi id=" . $_get["id"]; $rs = mysql_query($strsql); // loop recordset $rs while($row = mysql_fetch_array($rs)) { $id = $row['id']; ?> <tr> <td colspan="2" bgcolor="#cccccc"><b><center>seksyen - pengenalan artifak</center></b></td> </tr> <tr> <td width="40%"><b>tarikh penilaian:</b></td> <td width="60%"><?php echo $row['tarikh']; ?></td> </tr> <tr> <td width="40%"><b>lokasi penilaian:</b></td> <td width="60%"><?php echo $row['lokasi']; ?></td> </tr> <tr> <td width="40%"><b>no. pendaftaran:</b></td> <td width="60%"><?php echo $row['nopendaftaran']; ?></td> </tr> <tr> <td width="40%"><b>nama artifak:</b></td> <td width="60%"><?php echo $row['namaartifak']; ?></td> </tr> <tr> <td width="40%"><b>sumber koleksi:</b></td> <td width="60%"><?php echo $row['sumber']; ?></td> </tr> <tr> <td width="40%"><b>sumber pinjaman : </b></td> <td width="60%"><?php echo $row['sumberpinjaman']; ?></td> </tr> <tr> <td width="40%"><b>lain-lain sumber : </b></td> <td width="60%"><?php echo $row['lainlainsumber']; ?></td> </tr> <tr> <td width="40%"><b>kategori artifak: </b></td> <td width="60%"><?php echo $row['kategori']; ?></td> </tr> <tr> <td colspan="2"><b>ukuran</b></td> </tr> <tr> <td width="40%"><b>panjang: </b></td> <td width="60%"><?php echo $row['panjang']; ?></td> </tr> <tr> <td width="40%"><b>tinggi : </b></td> <td width="60%"><?php echo $row['tinggi']; ?></td> </tr> <tr> <td width="40%"><b>lebar: </b></td> <td width="60%"><?php echo $row['lebar']; ?></td> </tr> <tr> <td width="40%"><b>diameter: </b></td> <td width="60%"><?php echo $row['diameter']; ?></td> </tr> <tr> <td width="40%"><b>maklumat tambahan artifak: </b></td> <td width="60%"><?php echo $row['maklumattambahanartifak']; ?></td> </tr> <tr> <td colspan="2" bgcolor="#cccccc"><b><center>seksyen b- kondisi artifak</center></b></td> </tr> <tr> <td width="40%"><b>jenis koleksi : </b></td> <td width="60%"><?php echo $row['koleksi']; ?></td> </tr> <tr> <td width="40%"><b>lain-lain koleksi : </b></td> <td width="60%"><?php echo $row['lainlainkoleksi']; ?></td> </tr> </table> <table width="100%" cellpadding="3" cellspacing="1" border=1"> <tr> <td colspan="4"><b><center>jenis keroskan</center></b></td> </tr> <tr> <td colspan="2"><b><center>kerosakan struktur</center></b></td> <td colspan="2"><b><center>kerosakan permukaan</center></b></td> </tr> <tr> <td width="40%"><b>tiada kerosakan struktur : </b></td> <td width="10%"><?php echo $row['tiadakerosakan1']; ?></td> <td width="40%"><b>tiada kerosakan permukaan : </b></td> <td width="10%"><?php echo $row['tiadakerosakan2']; ?></td> </tr> <tr> <td width="40%"><b>retak : </b></td> <td width="10%"><?php echo $row['retak']; ?></td> <td width="40%"><b>calar : </b></td> <td width="10%"><?php echo $row['calar']; ?></td> </tr> <tr> <td width="40%"><b>patah : </b></td> <td width="10%"><?php echo $row['patah']; ?></td> <td width="40%"><b>mengelupas : </b></td> <td width="10%"><?php echo $row['mengelupas']; ?></td> </tr> <tr> <td width="40%"><b>hilang : </b></td> <td width="10%"><?php echo $row['hilang']; ?></td> <td width="40%"><b>melepuh : </b></td> <td width="10%"><?php echo $row['melepuh']; ?></td> </tr> <tr> <td width="40%"><b>bengkok : </b></td> <td width="10%"><?php echo $row['bengkok']; ?></td> <td width="40%"><b>pudar : </b></td> <td width="10%"><?php echo $row['pudar']; ?></td> </tr> <tr> <td width="40%"><b>sumbing : </b></td> <td width="10%"><?php echo $row['sumbing']; ?></td> <td width="40%"><b>kotor : </b></td> <td width="10%"><?php echo $row['kotor']; ?></td> </tr> <tr> <td width="40%"><b>longgar : </b></td> <td width="10%"><?php echo $row['longgar']; ?></td> <td width="40%"><b>karat : </b></td> <td width="10%"><?php echo $row['karat']; ?></td> </tr> <tr> <td width="40%"><b>lubang kecil : </b></td> <td width="10%"><?php echo $row['lubangkecil']; ?></td> <td width="40%"><b>lipatan : </b></td> <td width="10%"><?php echo $row['lipatan']; ?></td> </tr> <tr> <td width="40%"><b>rapuh : </b></td> <td width="10%"><?php echo $row['rapuh']; ?></td> <td width="40%"><b>kemek: </b></td> <td width="10%"><?php echo $row['kemek']; ?></td> </tr> <tr> <td width="40%"><b>mengecut : </b></td> <td width="10%"><?php echo $row['mengecut']; ?></td> <td width="40%"><b>kulat : </b></td> <td width="10%"><?php echo $row['kulat']; ?></td> </tr> <tr> <td width="40%"><b>kesan konservasi : </b></td> <td width="10%"><?php echo $row['kesankonservasi']; ?></td> <td width="40%"><b>kusam : </b></td> <td width="10%"><?php echo $row['kusam']; ?></td> </tr> <tr> <td width="40%"><b>jumlah kerosakan struktur (%) : </b></td> <td width="10%"><?php echo $row['jumlahstruktur']; ?></td> <td width="40%"><b>jumlah kerosakan permukaan (%) : </b></td> <td width="10%"><?php echo $row['jumlahpermukaan']; ?></td> </tr> <tr> <td colspan="3" width="90%"><b><center>kerosakan keseluruhan (%)</center></b></td> <td colspan="1" width="10%"><?php echo $row['total']; ?></td> </tr> <tr> <td colspan="1" width="40%"><b><center>kondisi artifak</center></b></td> <td colspan="3" width="60%"><?php echo $row['gred']; ?></td> </tr> <tr> <td colspan="1" width="40%"><b><center>maklumat tambahan kerosakan:</center></b></td> <td colspan="3" width="60%"><?php echo $row['maklumattambahankerosakan']; ?></td> </tr> <tr> <td colspan="4"><b><center>gambar artifak</center></b></td> </tr> <tr> <td colspan="1" width="40%"><b><center>gambar id :</center></b></td> <td colspan="3" width="60%">nota : <?php echo $row['gambaridnota']; ?> <br><br> <center><?php echo "<img src='".$row['gambarid']. "' height='300px' width='300px'/>";?></center> </td> </tr> <tr> <td colspan="4"><b><center>bahagian-bahagian objek</center></b></td> </tr> <tr> <td colspan="2" width="50%"><center><b>depan</b></center> <br> keterangan : <?php echo $row['keterangandepan']; ?> <br><br> <center><?php echo "<img src='".$row['depan']. "' height='300px' width='300px'/>";?></center> <td colspan="2" width="50%"><center><b>belakang </b></center><br> keterangan : <?php echo $row['keteranganbelakang']; ?> <br><br> <center><?php echo "<img src='".$row['belakang']. "' height='300px' width='300px'/>";?></center> </td> </tr> <tr> <td colspan="2" width="50%"><center><b>atas</b></center> <br> keterangan : <?php echo $row['keteranganatas']; ?> <br><br> <center><?php echo "<img src='".$row['atas']. "' height='300px' width='300px'/>";?></center> <td colspan="2" width="50%"><center><b>bawah </b></center><br> keterangan : <?php echo $row['keteranganbawah']; ?> <br><br> <center><?php echo "<img src='".$row['bawah']. "' height='300px' width='300px'/>";?></center> </td> </tr> <tr> <td colspan="2" width="50%"><center><b>gambar close 1</b></center> <br> keterangan : <?php echo $row['keterangancloseup1']; ?> <br><br> <center><?php echo "<img src='".$row['closeup1']. "' height='300px' width='300px'/>";?></center> <td colspan="2" width="50%"><center><b>gambar close 2</b></center><br> keterangan : <?php echo $row['keterangancloseup2']; ?> <br><br> <center><?php echo "<img src='".$row['closeup2']. "' height='300px' width='300px'/>";?></center> </td> </tr> </table> <table width="100%" cellpadding="3" cellspacing="1" border=1"> <tr> <td colspan="4" bgcolor="#cccccc"><b><center>seksyen c- cadangan rawatan/tindakan konservasi</center></b></td> </tr> <tr> <td width="40%"><b>cadangan rawatan : </b></td> <td width="60%"><?php echo $row['rawatan']; ?></td> </tr> <tr> <td width="40%"><b>lain-lain rawatan : </b></td> <td width="60%"><?php echo $row['lainlainrawatan']; ?></td> </tr> <tr> <td colspan="4"><b><center>laporan disediakan oleh</center></b></td> </tr> <tr> <td width="40%"><b>nama pegawai 1 : </b></td> <td width="60%"><?php echo $row['pegawai1']; ?></td> </tr> <tr> <td width="40%"><b>nama pegawai 2 : </b></td> <td width="60%"><?php echo $row['pegawai2']; ?></td> </tr> <table width="100%" border="1" cellspacing="1" cellpadding="5"> <tr> <td colspan="4" bgcolor="#cccccc"><b><center>kondisi objek diperiksa oleh</center></b></td> </tr> <tr> <td width="102" rowspan="2" valign="top"><center><p> </p> <p><strong>receive/</strong><br><i>penerimaan</i></p> </center></td> <td width="236" rowspan="2" valign="top"> <center><p><strong>condition upon unpacking</strong></center></strong> o <strong>condition unchange</strong>/ tiada perubahan<br> o <strong>condition change</strong>/ berubah</p></td> <td width="142" valign="top"><center><p><strong></strong></p></center></td> <td width="137" valign="top"><p><strong> </strong></p></td> </tr> <tr> <td width="142" valign="top"><p><strong> </strong></p></td> <td width="137" valign="top"><p><strong> </strong></p></td> </tr> <tr> <td width="102" rowspan="4" valign="top"><center><p> </p> <p><strong>return/</strong><br><i>pemulangan</i></p> </center></td> <td width="236" rowspan="2" valign="top"> <center><p><strong>condition upon repacking</strong></center></strong> o <strong>condition unchange</strong>/ tiada perubahan<br> o <strong>condition change</strong>/ berubah</p></td></td> <td width="137" valign="top"><p><strong> </strong></p></td> <td width="215" valign="top"><p><strong> </strong></p></td> </tr> <tr> <td width="142" valign="top"><center><p><strong></strong></p></center></td> <td width="137" valign="top"><p><strong> </strong></p></td> </tr> <tr> <td width="236" rowspan="2" valign="top"> <center><p><strong>condition upon unpacking</strong></center></strong> o <strong>condition unchange</strong>/ tiada perubahan<br> o <strong>condition change</strong>/ berubah</p></td></td> <td width="137" valign="top"><center><p><strong></strong></p></center></td> <td width="215" valign="top"><p><strong> </strong></p></td> </tr> <tr> <td width="142" valign="top"><center><p><strong></strong></p></center></td> <td width="137" valign="top"><p><strong> </strong></p></td> </tr> </table> <p> </p> <p><a href="form7.php">return list</a></p> <?php } ?> </tbody> </form>
i'm doing simple registration system. here attached picture before , after upload picture , retrieve database.
my question in form got few upload picture buttons , not pictures uploaded everytime. in report, can see pictures uploaded , see broken image picture because picture not uploaded.
so how hide broken image icon?
you can load default image when image not found using onerror,
<img src="image.jpg" alt="image not found" onerror="this.onerror=null;this.src='default.jpg';" />
you can hide image following code,
<img onerror='this.style.display = "none"'>
Comments
Post a Comment