Friday, 14 October 2011

tugas 1 web dinamis


Home.php
                                <table class='main' cellpadding=0 cellspacing=0 border=1 style="color:#fff">
                                <tr height="25px" bgcolor="#000">
                                <td width='100' align='center'><b>Kode</b></td>
                                <td width='300' align='center'><b>Nama</b></td>
                <td width='100' align='center'><b>Harga</b></td>
                                </tr>
                                </table>
<?php
                                $qry=mysql_query("select * from barang");                                      
                                print "<table cellpadding=1 cellspacing=1 style='border:solid 0px #999'>";
                                while ($row=mysql_fetch_array($qry)){
?>
                                <tr height="25px" cellpadding=0 cellspacing=0 bgcolor="#F8F8F8" border="1px" style="border:solid 1PX #000">
                                <td width='100' align='right'>      <?php print $row[bkode]?></td>
                <td width='300' align='left'>        <?php print $row[bnama]?></td>
                                <td width='100' align='center'>  <?php print number_format($row[bharga])?></td>
                                </tr>
<?php
                                }
?>
                                </table>

Output




Tambah.php
<?php
if (isset($_POST['save'])){
                if (empty($_POST['bkode'])) {
?>
                                <script language="javascript">
                                                alert("Kode Barang kosong!");
                                </script>
<?php
                }
                else if (empty($_POST['bnama'])) {
?>
                                <script language="javascript">
                                                alert("Nama Barang kosong!");
                                </script>
<?php  
                }
                else if (empty($_POST['bharga'])) {
?>
                                <script language="javascript">
                                                alert("Harga Barang kosong!");
                                </script>
<?php  
                }
                else {
                                FUNCTIONS_SAVE($_POST[bkode],$_POST[bnama],$_POST[bharga]);
                }
}
else if(isset($_POST['cancel'])){
?>
<script type="text/javascript">
        self.location.href ="index.php";
</script>
<?php
}
?>
<form action="?n=tambah" method=POST>
<table border=0 cellpadding=0 cellspacing=0 style="border:solid 0px #000;color:#000">
                <tr>
                                <td colspan='5'height='10'></td>
                </tr>
                <tr>
                                <td width='10'></td>
                                <td width='90'><b>Kode </b></td>
                                <td width='3'>:</td>
                                <td width='160'><input type="text"        name="bkode" size=15 maxlength=6 tabindex=1 value=""></h3></td>
                </tr>
                <tr>
                                <td colspan='5' height='2'></td>
                </tr>
                <tr>
                                <td></td>
                                <td><b>Nama </b></td>
                                <td>:</td>
                                <td><input type="text"                 name="bnama" size=30 maxlength=128 tabindex=2 value=""></h3></td>
                </tr>
                <tr>
                                <td colspan='5' height='2'></td>
                </tr>
                <tr>
                                <td></td>
                                <td><b>Harga</b></td>
                                <td>:</td>
                                <td><input type="text"                 name="bharga" size=30 maxlength=35 tabindex=3 value=""></h3></td>
                </tr>
                <tr>
                                <td colspan='5' height='2'></td>
                </tr>
                <tr>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td>
                                <button name="save" style="border: 1px solid #666; background-color:#fff" tabindex=8>&nbsp;Save&nbsp;</button>
                                <button name="cancel" style="border: 1px solid #666; background-color:#fff" tabindex=9>&nbsp;Cancel&nbsp;</button>
                                </td>
                </tr>
                <tr>
                                <td colspan='5'height='10'></td>
                </tr>
</table>
</form>
Output


Edit.php
<?php
if (isset($_POST['save'])){
                if (empty($_POST['bnama'])) {
?>
                                <script language="javascript">
                                                alert("Nama Barang kosong!");
                                </script>
<?php  
                }
                else if (empty($_POST['bharga'])) {
?>
                                <script language="javascript">
                                                alert("Harga Barang kosong!");
                                </script>
<?php  
                }
                else {
                                FUNCTIONS_UPDATE($_POST[bid],$_POST[bnama],$_POST[bharga]);
?>
<script type="text/javascript">
        self.location.href ="index.php";
</script>
<?php
                }
}
else if(isset($_POST['cancel'])){
?>
<script type="text/javascript">
        self.location.href ="?n=edit";
</script>
<?php
}
else {
                $bid=$_GET[edit];
                $qry=mysql_query("select * from barang where bkode='$bid'");
                $row=mysql_fetch_array($qry);              
}
?>
<form action="?n=edit_s" method=POST>
<table border=0 cellpadding=0 cellspacing=0 style="border:solid 0px #000;color:#000">
                <tr>
                                <td colspan='5'height='10'></td>
                </tr>
                <tr>
                                <td width='10'></td>
                                <td width='90'><b>Kode </b></td>
                                <td width='3'>:</td>
                                <td width='160'><input type="text"        name="bkode" disabled='disabled' size=15 maxlength=6 tabindex=1 value="<?php print $bid ?>"></h3></td>
                </tr>
                <tr>
                                <td colspan='5' height='2'></td>
                </tr>
                <tr>
                                <td></td>
                                <td><b>Nama </b></td>
                                <td>:</td>
                                <td><input type="text"                 name="bnama" size=30 maxlength=128 tabindex=2 value="<?php print $row[bnama] ?>"></h3></td>
                </tr>
                <tr>
                                <td colspan='5' height='2'></td>
                </tr>
                <tr>
                                <td></td>
                                <td><b>Harga</b></td>
                                <td>:</td>
                                <td><input type="text"                 name="bharga" size=30 maxlength=35 tabindex=3 value="<?php print $row[bharga] ?>"></h3></td>
                </tr>
                <tr>
                                <td colspan='5' height='2'></td>
                </tr>
                <tr>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td>
                                <button name="save" style="border: 1px solid #666; background-color:#fff" tabindex=8>&nbsp;Save&nbsp;</button>
                                <button name="cancel" style="border: 1px solid #666; background-color:#fff" tabindex=9>&nbsp;Cancel&nbsp;</button>
                                <input name='bid' type='hidden' value="<?php print $bid ?>">
                                </td>
                </tr>
                <tr>
                                <td colspan='5'height='10'></td>
                </tr>
</table>
</form>
Output




Hapus.php
<?php
                if (!empty($_GET[hapus])) {
                                FUNCTIONS_HAPUS($_GET[hapus]);
                }
?>
                                <table class='main' cellpadding=0 cellspacing=0 border=1 style="color:#fff">
                                <tr height="25px" bgcolor="#000">
                                <td width='100' align='center'><b>Kode</b></td>
                                <td width='300' align='center'><b>Nama</b></td>
                <td width='60' align='center'><b>Hapus</b></td>
                                </tr>
                                </table>
<?php
                                $qry=mysql_query("select * from barang");                                      
                                print "<table cellpadding=1 cellspacing=1 style='border:solid 0px #999'>";
                                while ($row=mysql_fetch_array($qry)){
?>
                                <tr height="25px" cellpadding=0 cellspacing=0 bgcolor="#F8F8F8" border="1px" style="border:solid 1PX #000">
                                <td width='100' align='right'>      <?php print $row[bkode]?></td>
                <td width='300' align='left'>        <?php print $row[bnama]?></td>
<?php
                                print "<td width='60' align='center'><a href='./?n=hapus&&hapus=$row[bkode]'>Hapus</a></td>";
                                }
?>
                                </table>
Output

No comments:

Post a Comment