[php]insert data ke database

oke guys, back to coding again..

tempo hari saya sudah berbagi tutorial mengenai membuat site form HTML yang berfungsi untuk menampung data form user. sekarang saatnya kita membuat file php untuk insert data form tadi ke database/

berikut sample codingnya

include "koneksidb.php";

if($_POST['kirim'] == "send")
{

$NIM = $_POST['nim'];
$nama = $_POST['nama'];
$alamat = $_POST['alamat'];
$divisi = $_POST['divisi'];
$hp = $_POST['hp'];

if($NIM != "" and $nama != "" and $alamat != "" and $hp != "" and $divisi != "")
{
$sql = "INSERT INTO daftar_panitia VALUES('No.','$NIM','$nama','$hp','$alamat','$divisi')";
mysql_query($sql);

if(mysql_errno() == 0){
echo"alert('Register sucessfull!, data saved');";
}else{
echo"alert('Register failed!');";
}
}else{
echo"alert('Register failed!');";
}
}

keterangan
variable $sql = sql untuk input data ke database (valuenya tergantung temen2)
mysql_errno() = php akan menseleksi apabila ada yg eror dalam pernyataan sql
jangan lupa untuk include file koneksi database yang sudah ane share tempo hari

selamat bercoding ria.. coding is not a crime -,-v

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s