<?php
	include ("../inc/koneksi.php");
	include('../inc/password.php');
	
	$nama = mysql_real_escape_string($_POST['nama']);
	$email = mysql_real_escape_string($_POST['email']);
	$telp = mysql_real_escape_string($_POST['telp']);
	$username = mysql_real_escape_string($_POST['username']);
	$password = mysql_real_escape_string($_POST['password']);

	$pass_hash = password_hash($password, PASSWORD_BCRYPT);
	$wrong = "";

	$cek_email = mysql_query("SELECT * FROM user WHERE email = '$email'");
	$n_email = mysql_num_rows($cek_email);

	$cek_user = mysql_query("SELECT * FROM user WHERE username = '$username'");
	$n_user = mysql_num_rows($cek_user);

	if ($n_email == 1) {
		$wrong = "ada";
	}
	elseif ($n_user == 1) {
		$wrong = "username";
	}
	else
	{
		//simpan ke dalam user
		$query = "INSERT INTO user (nama,email,telp,username,password) VALUES ('$nama','$email','$telp','$username','$pass_hash')";		
		mysql_query($query) or die (mysql_error());
	}

	if($wrong == "")
		$url = "registrasi.php?ket=berhasil";
	else
		$url = "registrasi.php?ket=$wrong";

	echo "<script language=\"javascript\">
		window.location='$url';
	</script>";

?>