Selasa, 04 Desember 2012

Modul 8 KKPI : Pengenalan Internet



Cara Membuat Web dengan PHP

Hypertext Preprocessor atau yang sering disebut PHP merupakan bahasa skrip yang dapat disisipkan atau ditanamkan ke dalam HTML. PHP juga sering kita jumpai dalam pembuatan situs web dinamis, selain itu PHP juga dapat digunakan untuk membangun sebuah CMS. Sedangkan PHP pertama kali dibuat oleh Rasmus Lerdorf pada tahun 1995.

1. kitabuat script PHP sepertiberikut :

· Index.php

 
<html>
<head>
<title>WELCOME</title>
</head>
<body background="cr.jpg">
<?php
echo "
<head><body background=\"3\"><title>SELAMAT DATANG DI SEKOLAH KITA</title>

<style type=\"text/css\">
div.front-welcome-text {margin: 100px 150px 250px 150px;}
</style>
      <div class=\"front-welcome-text\">
<h2><p><font color=\"white\">SELAMAT DATANG DI SEKOLAH KITA</font></p></h2>
<h3><p><font color=\"white\">Temukan apa saja yang anda mau, tapi kalau ada.</font></p></h3>
</div>
<style type=\"text/css\">
div.front-welcome-text {margin: 100px 250px 125px 150px;}
</style>
      <div class=\"front-welcome-text\">
<tr><td></td>
<td><a href=\"output.php\"><input type=submit name=\"Daftar Siswa\" value=\"Daftar Siswa\"></a><br>
<td><a href=\"cari.php\"><input type=submit name=\"Pencarian Data Siswa\" value=\"Pencarian Data Siswa\"></a><br>
<td><a href=\"input.php\"><input type=submit name=\"Absen Siswa\" value=\"Absen Siswa\"></a><br>
</td></td></tr>
</table>
</div>

</body>";
?>

</body>
</html>

Dan hasilnyaadalahsepertiberikut :

2. Membuat script absen siswa (inpt.php)
<?php
echo "<html>
<head>
<body background=\"Dell.jpg\">
<p align=\"center\" class=\"style1\"></p>
<table width=\"448\" height=\"219\" border=\"10\" align=\"center\" cellpadding=\"7\" cellspacing=\"1\" bgcolor=\"black\" style=\"margin-top:50px;\">
  <form action=\"index1.php\" method=\"post\">
    <tr bgcolor=\"#CCCCCC\">
      <td colspan=\"2\" align=\"center\" \"><b>ABSEN Disini</b></td>
    </tr>
    <tr bgcolor=\"black\">
      <td width=\"60\" bordercolor=\"white\" \"><font color=\"white\">Nama </font></td>
      <td width=\"202\" bordercolor=\"white\" \"><input name=\"Nama\" type=\"text\" size=\"45\" required=\"required\" placeholder=\"Tuliskan Nama..\"/></td>
    </tr>
    <tr bgcolor=\"black\">
      <td bordercolor=\"#FFFFFF\" \"><font color=\"white\">Kelas  </font></td>
      <td bordercolor=\"#FFFFFF\" \"><input name=\"Kelas\" type=\"text\" size=\"45\" required=\"required\" placeholder=\"Tuiskan Kelas..\"/></td>
    <tr bgcolor=\"black\">
      <td bordercolor=\"#FFFFFF\" \"><font color=\"white\">Jurusan  </font></td>
      <td bordercolor=\"#FFFFFF\" \"><input name=\"Jurusan\" type=\"text\" size=\"45\" required=\"required\" placeholder=\"Tuliskan jurusan..\"/></td>
    </tr>
<tr bgcolor=\"black\">
      <td width=\"60\" bordercolor=\"#FFFFFF\" \"><font color=\"white\">NIS </font></td>
      <td width=\"202\" bordercolor=\"#FFFFFF\" \"><input name=\"NIS\" type=\"text\" size=\"45\" required=\"required\" placeholder=\"Masukkan NIS..\"/></td>
    </tr>
    </tr>
    <tr bgcolor=\"black\">
      <td colspan=\"2\" align=\"center\" \"><input type=\"submit\" name=\"Submit\" value=\"ABSEN\" />
       <a href=\"output.php\"><input type=\"button\" value=\"LIHAT SISWA\" align=\"center\"></a></td>
    </tr>
  </form>
</table>
</body>
</head>
</html>";
?>

Buat script untuk meng koneksikan absen siswa
<?php
$kom = "localhost";
$user = "root";
$pass = "dito";
$data = "input.php";
$sambung=mysql_connect($kom,$user,$pass);
$pilih=mysql_select_db($data);

include('input.php');

$A = $_POST [Nama];
$B = $_POST [Kelas];
$C = $_POST [Jurusan];
$D = $_POST [NIS];
$Q = "INSERT INTO `dito fahmi`.`absen siswa` (
`Nama` ,
`Kelas` ,
`Jurusan` ,
`NIS`
)
VALUES (
'$A', '$B', '$C', '$D'
)";
$H = mysql_query ($Q);

echo "<p align=\"center\" class=\"style2\"><blink>TERIMA KASIH ANDAH BERHASIL ABSEN HARI INI</blink></p>";

?>

Dan hasilnyaadalahsepertiberikut :

3. Membuat hasil inputan output.php
<?php
$user                = "root";
$password       = "dito";
$komputer       = "localhost";
$data                = "dito fahmi";

$sambung        = mysql_connect($komputer,$user,$password);
$pilih               = mysql_select_db($data);
$cari                = "SELECT * FROM `absen siswa` WHERE 'Nama' like '%'" ;
$a=mysql_query($cari);
echo "<html>
<body background=\"Dell.jpg\">
<body>
<table align=center border=10 cellpadding=20 cellspacing=5>
<tr>
            <th bgcolor=\"black\"><font color=\"white\">Nama </font></th>
        <th bgcolor=\"black\"><font color=\"white\">kelas </font></th>
        <th bgcolor=\"black\"><font color=\"white\">Jurusan </font></th>
        <th bgcolor=\"black\"><font color=\"white\">NIS </font></th>
            <th bgcolor=\"black\"><font color=\"white\">OPSI </font></th>

</tr>";
$while= mysql_query("SELECT * FROM `absen siswa` ORDER BY NIS");
            $no=1;


            while($data = mysql_fetch_array ($while)) {
            echo "<tr>
            <td>$data[0]</td>
            <td>$data[1]</td>
            <td>$data[2]</td>
            <td>$data[3]</td>
            <th>
            <a href=edit.php?Nama=$data[Nama]><input type=submit value='edit' align=center></a>
            <a href=\"delete.php?Nama=$data[Nama]\"onClick=\"return confirm('Anda yakin ingin menghapus $data[Nama]?')\"><input type=submit value='delete' align=center></a>
            </th>
            </tr>";
}
echo " <p align=\"center\"><font colour=\"#FFFFF\"><a href=\"index.php\">KELUAR</a></font></p>";
echo " <p align=\"center\"><font colour=\"#FFFFF\"><a href=\"recovery_data.php\">RESTORE</a></font></p>";
echo " <p align=\"center\"><font colour=\"#FFFFF\"><a href=\"backup.php\">Backup data</a></font></p>";
echo "
</table>
</body>
</html>";
?>


HASILNYA

4. Script pencarian siswa cari.php
<html>
<head>
<body background="Dell.jpg">
<title> Pencarian </title>
</head>
<body>
<form name="formcari" method="post" action="hasil-pencarian.php">
<table width="330" border="0" align="center" cellpadding="0">
<tr bgcolor="grey">
<td height="35" colspan="10">
<strong><p align="center"> PENCARIAN </p></strong>
</td>
</tr>
<tr> <th>Nama Siswa</th>
<td> <input type="text" name="Nama" size="25" required="required" placeholder="Tuliskan Nama Siswa.."> </td>
</tr>
<td></td>
<td> <input type="SUBMIT" name="SUBMIT" id="SUBMIT" value="cari" > </td>
</table>
</form>
</body>
</html>

Dan hasilnyaadalahsepertiberikut :


5. Lalu buat script hasil pencarian
<html>
<head>
<title>Hasil pencarian</title>
</head>
<body background="Dell.jpg">
<?php
$user="root";
$pass="dito";
$kom="localhost";
$data="dito fahmi";

$sambung=mysql_connect($kom,$user,$pass);
$pilih=mysql_select_db($data);
$nama=$_POST['Nama'];
$q="SELECT * from `absen siswa` where nama like '%$nama%' ";
$result=mysql_query($q);
echo "<center>";
echo "<h2>Hasil Pencarian</h2>";
echo "<table border='5' cellpadding='5' cellspacing='5'>";
echo "
<tr bgcolor='black'>
            <th bgcolor=\"black\"><font color=\"white\">Nama </font></th>
        <th bgcolor=\"black\"><font color=\"white\">kelas </font></th>
        <th bgcolor=\"black\"><font color=\"white\">Jurusan </font></th>
        <th bgcolor=\"black\"><font color=\"white\">NIS </font></th>
            <th bgcolor=\"black\"><font color=\"white\">OPSI </font></th>
</tr>";
$i=0;
while ($data = mysql_fetch_array ($result)) {
$i++ ;
echo "
<tr>
            <td>$data[0]</td>
            <td>$data[1]</td>
            <td>$data[2]</td>
            <td>$data[3]</td>
            <th>
            <a href=edit.php?Nama=$data[Nama]><input type=submit value='edit' align=center></a>
            <a href=\"delete.php?Nama=$data[Nama]\"onClick=\"return confirm('Anda yakin ingin menghapus $data[Nama]?')\"><input type=submit value='delete' align=center></a>
            </th>
</tr>";
}
echo "</table>";
echo "<a href=\"cari.php\"><input type=\"button\" value='Kembali' align=center></a>";
echo "<a href =\"index.php\"><input type=submit name=Coba Lagi value='Keluar'></a></td></tr></h2>";
?>
</body>
</html>
Hasilnya

6. Membuat script delete.php
<?php

$user="root";
$pass="dito";
$kom="localhost";
$data="dito fahmi";

$sambung= mysql_connect ( $kom,$user,$pass );
$pilih= mysql_select_db( $data );

$hapus=mysql_query("DELETE FROM `absen siswa` WHERE Nama='$_GET[Nama]'");
header('location:output.php');

?>

7. Membuat edit.php
<html>
<head>
<title>Edit Data</title>
</head>
<body background="Dell.jpg">
<?php
$user="root";
$pass="dito";
$kom="localhost";
$data="dito fahmi";

$sambung= mysql_connect ( $kom,$user,$pass );
$pilih= mysql_select_db( $data );

    $edit = mysql_query("SELECT * FROM `absen siswa` WHERE Nama='$_GET[Nama]'");
   $data = mysql_fetch_array($edit);
    echo  "<form method=POST action=upload.php>
          <input type=hidden name=Nama value='$data[Nama]'>
          <table align=center border=0 cellpadding=20>
                          <tr><th colspan=2><font size='6'>Edit Data Siswa</font></h1></th></tr>
              <tr><th align=right>Nama </th><td> : <input type='text' maxlength='10' name='Nama' value='$data[Nama]' disabled></td></tr>
                  <tr><th align=right>Kelas </th><td> : <input type='text' maxlength='15' name='Kelas' value='$data[Kelas]' required=\"required\"></td></tr>
                          <tr><th align=right>Jurusan </th><td> : <input type='text' maxlength='30' name='Jurusan' value='$data[Jurusan]' required=\"required\"></td></tr>
                          <tr><th align=right>NIS </th><td> : <input type='text' maxlength='30' name='NIS' value='$data[NIS]' required=\"required\"></td></tr>
          </td></tr>
                                          
        
          </table>
          <h2 align=center>
          <input type=submit value=upload>
          <input type=button value=Batal onclick=self.history.back()>
          </form></h2>";
?>
</body>
</html>

Dan hasilnyaadalahsepertiberikut :

8. Membuat script upload sesudah mengedit (upload.php)
<html>
<body background="Dell.jpg">
<?php

$user="root";
$pass="dito";
$kom="localhost";
$data="dito fahmi";

$sambung= mysql_connect ( $kom,$user,$pass );
$pilih= mysql_select_db( $data );

$update= mysql_query ("UPDATE `absen siswa` SET Nama='$_POST[Nama]',Kelas='$_POST[Kelas]',Jurusan='$_POST[Jurusan]',NIS='$_POST[NIS]' WHERE Nama='$_POST[Nama]'");


if($update) {
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
            echo "<class=\"style2\"><blink><h3 align=\"center\"><font color=\"red\">DATA TERSIMPAN</h3></font></blink></p>";;
}
else {
            echo "<class=\"style2\"><blink>Data Tidak Bisa Tersimpan</blink></p>";
}                                                                     
?>
<br>
<h2 align=center>
<a href="index.php"><input type="button" value='KELUAR'></a>
<a href ="output.php"><input type=submit name=Tabel value=TABEL></a>
</h2>";
</td></tr>
</body>
</html>

Dan hasilnya adalah sepertiberikut :





SEKIAN

Tidak ada komentar:

Posting Komentar