friendship

friendship

Monday, February 20, 2012

connect, POST, GET php dan HTML.


Connect:


<?php
$check = mysql_connect("localhost","root","")
or die("koneksi gagal ");

if($check == true)
{
print "Welcome to xampp ";
$kondisi = mysql_select_db("latihan");

if($kondisi == true)
{
print "DataBase Terhubung";
}

}
?>
============================
POST php dan HTML:


<html>
<head><title> form tambahan </title> </head>
<body>
<form action ='' method=post>
<p>NIM: <input type ='text' name ='nim' /></br></p>
<p>Nama: <input type ='text' name ='nama' /></br></p>
<p>Alamat: <input type ='text' name ='alamat' /></br></p>
<input type = 'submit' nama='simpan' value= 'simpan' />
</form>
</html>
<?php
if($_POST)
{
print"<h1>Nim : ".$_POST['nim']."<br>";
print"<h1>Nama : ".$_POST['nama']."<br>";
print"<p><h1>Alamat : ".$_POST['alamat']."<br></p>";

include "connect.php";
$sql = "INSERT INTO mahasiswa (nim, nama, alamat)
VALUES('$_POST[nim]','$_POST[nama]','$_POST[alamat]')";

mysql_query($sql) or die (mysql_error() );
print"<h1>Data Tersimpan";

}
?>
============================
GET php dan HTML:


<html>
<head><title> form tambahan </title> </head>
<body>
<form action ='' method=get>
<p>NIM: <input type ='text' name ='nim' /></br></p>
<p>Nama: <input type ='text' name ='nama' /></br></p>
<p>Alamat: <input type ='text' name ='alamat' /></br></p>
<input type = 'submit' nama='simpan' value= 'simpan' />
</form>
</html>
<?php
if($_GET)
{
print"<h1>Nim : ".$_GET['nim']."<br>";
print"<h1>Nama : ".$_GET['nama']."<br>";
print"<h1>Alamat : ".$_GET['alamat']."<br>";
}
?>