Pages

Banner 468 x 60px

 

Saturday 29 December 2012

PHP Pemula

0 comments
    LATIHAN PHP


Mangga yang mau belajar, monggo di copas

<form name="form1" method="post" action="fungsi.php">
  <table width="49%" border="1">
    <tr>
      <td width="24%">nip</td>
      <td width="76%"><label>
        <input name="nip" type="text" id="nip">
      </label></td>
    </tr>
    <tr>
      <td>nama</td>
      <td><label>
        <input name="nama" type="text" id="nama">
      </label></td>
    </tr>
    <tr>
      <td>alamat</td>
      <td><label>
        <textarea name="alamat" id="alamat"></textarea>
      </label></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><label>
        <input type="submit" name="Submit" value="input">
      </label></td>
    </tr>
  </table>
</form>

Simpanya        = formulir.php
====================================================
<?php
//koneksi
mysql_connect("localhost","root","");
mysql_select_db("dbpegawai");

//sql query input
$sql="insert into tblpegawai values ('001','rudi','tasik')";
$hasil=mysql_query($sql);

//pindah halaman
header("location:tampil.php");
?>

Simpanya        = pungsi.php
====================================================
<table width="100%" border="1">
  <tr>
    <td>nip</td>
    <td>nama</td>
    <td>alamat</td>
  </tr>

<?php
//koneksi
mysql_connect("localhost","root","");
mysql_select_db("dbpegawai");

//tampil
$sql="select * from tblpegawai";
$hasil=mysql_query($sql);
while ($baris=mysql_fetch_array($hasil))
{ echo "
<tr>
<td>$baris[nip]</td>
    <td>$baris[nama]</td>
    <td>$baris[alamat]</td>
  </tr>
";
}
?>
</table>

Simpanya        = tampil.php

0 comments:

Post a Comment