Monday, November 26, 2012

membuat web dengan php dan mysql


File di dalam htdocnya



Homepage

 View data page
xampp untuk menjalankan webnya

 
 Biodata page






SOURCE :



file connec : <?php

$user = "root";

$host = "localhost";

$pass = "";

$dbname = "gunadarma";

mysql_connect("$host","$user","$pass") or die ("error");

mysql_select_db("$dbname") or die ("no databases");

?>



File biodata : <html>

<head><title>biodata</title></head>

<body>

<form name="form1" method="post" action="">

<p>Npm : <input name="txtnpm" type="text" id="txtnpm"></p>

<p> Nama :<input name="txtnm" type="text" id="txtnm"></p>

<p>kelas :<input type="text" name="txtkelas" id="txtkelas"></p>

<p>alamat :</p>

<p> <textarea name="almt" id="almt" cols="45" rows="5"></textarea><input type="submit" name="save" id="save" value="Simpan"></p>

<p>&nbsp; </p></form></body>

</html>

<?php

require "connect.php";

if (isset($_POST['save'])){

$npm=$_POST['txtnpm'];

$nama=$_POST['txtnm'];

$kelas=$_POST['txtkelas'];

$alamat=$_POST['almt'];

$sql_cmd="INSERT INTO mahasiswa VALUES($npm,'$nama','$kelas','$alamat')";

if (mysql_query("$sql_cmd")){

echo "tersimpan";}

else{echo"Terjadi error";}

}

?>



File view : <html>

<head><title></title></head>

<body>

<table width="1083" height="29" border="1">

<tr>

<td width="232" height="23" align="center">NPM</td>

<td width="330" align="center">Nama</td>

<td width="125"align="center" >Kelas</td>

<td width="368"align="center" >Alamat</td>

</tr>

</table>

</body>

</html>

<?php

include "connect.php";

$sql_cmd="SELECT * FROM mahasiswa";

$squery=mysql_query($sql_cmd);

while ($hasil=mysql_fetch_array($squery)){

$npm=$hasil['npm'];

$nama=$hasil['nama'];

$kelas=$hasil['kelas'];

$alamat=$hasil['alamat'];

echo"

<table width='1083' height='29' border='1'>

<tr>

<td width='232' height='23' align='center'>$npm</td>

<td width='330' align='center'>$nama</td>

<td width='125'align='center' >$kelas</td>

<td width='368'align='center' >$alamat</td>

</tr>

</table>";}

?>





Logika :

- Web ini menggunakan frame, php dan mysql

- Buat koneksi database <source diatas> dan simpan di dalam file connec.php

- Untuk home.php menggunakan text area dan gambar

- Untuk file biodata.php sourcenya ada diatas dan membutuhkan file connect.php untuk koneksi ke database agar bisa menginput datanya

- Sama halnya dengan file view.php juga menggunakan connect.php hanya saja file view.php digunakan untuk mencetak database yang telah disimpan

No comments:

Post a Comment