Rabu, 02 Maret 2011

Latihan Ujian Praktek Komputer

mysql -h 192.168.0.64 -u 12ax-yy -p
use db12a3_yy;
create table coba(id int(50), nama varchar(50), email varchar(255), hadiah varchar(50), warna varchar(50), primary key(id));
masuk.php
<html>
 <head>
 <style type=text/css>
  B {color:blue; font-style:italic;text-decoration:line-through}
 </style>
</head>
<body>
 <B>Penjualan Pernak Pernik Online</B>
 <pre>
 <form method=post action=jadi.php>
 Nama    : <input type=text name=nama>
 Email   : <input type=text name=nama>
 Hadiah  : <input type=radio name=hadiah value=Boneka>Boneka
     <input type=radio name=hadiah value=Bunga >Bunga
     <input type=radio name=hadiah value=Baju  >Baju
           <input type=radio name=hadiah value=Pita  >Pita
 Warna   : <select name=warna>
 <?
  $d=array(5=>"Biru","Kuning","Merah","Hitam","Putih");
   for($x=5;$x<=8;$x++)
  {
   echo "<option value=$d[$x]>$d[$x]";
  }
 ?>
    </select>
 <input type=submit value=Pesan>
 </form>
 <form method=post action=search.php>
 <input type=text name=nama>
 <input type=submit value=search>
 </form>
 </pre>
</body>
</html>

jadi.php
<?
$nama   =$_POST['nama'];
$email  =$_POST['email'];
$hadiah =$_POST['hadiah'];
$warna  =$_POST['warna'];
mysql_connect("192.168.0.64","12ax-yy","1234");
mysql_select_db("db12a3_yy") or die("Database Not Found");
$hsl=mysql_query("insert into coba(nama,email,hadiah,warna) values ('$nama','$email','$hadiah','$warna')");
$d=mysql_query("select * from coba where hadiah='Boneka'");
$bo=mysql_num_rows($hsl);
$d=mysql_query("select * from coba where hadiah='Bunga'");
$bu=mysql_num_rows($hsl);
$d=mysql_query("select * from coba where hadiah='Baju'");
$ba=mysql_num_rows($hsl);
$d=mysql_query("select * from coba where hadiah='Pita'");
$pi=mysql_num_rows($hsl);
$tot=$bo+$bu+$ba+$pi;
$hsl=mysql_query("select * from coba");
while($d=mysql_fetch_array($hsl))
{
 echo "<pre>";
 echo "Nama   : $d[nama]   <br>";
 echo "Email  : $d[email]  <br>";
 echo "Hadiah : $d[hadiah] <br>";
 echo "Warna  : $d[warna]  <br>";
}
 echo "Banyak orang yang suka Boneka :".$bo/$tot*100"%<br>";
 echo "Banyak orang yang suka Bunga  :".$bu/$tot*100"%<br>";
 echo "Banyak orang yang suka Baju   :".$ba/$tot*100"%<br>";
 echo "Banyak orang yang suka Pita   :".$pi/$tot*100"%<br>";
?>
search.php
<?
$nama=$_POST['nama'];
mysql_connect("192.168.0.64","12ax-yy","1234");
mysql_select_db("db12a3_yy") or die("Database Not Found");
$hasil=mysql_query("select * from coba where nama like '%$nama%'");
while($d=mysql_fetch_array($hasil))
{
 echo "Email  :  $d[email]  <br>";
 echo "Hadiah :  $d[hadiah] <br>";
 echo "Warna  :  $d[warna]  <br>";
}
?>

Tidak ada komentar:

Posting Komentar