<?php
	session_start();
	include 'koneksi.php';
	if(isset($_POST['daftar'])){
		$role			= 2;
		$nama_lengkap	= $_POST['nama_lengkap'];
		$alamat			= $_POST['alamat'];
		$nomor_ponsel	= $_POST['nomor_ponsel'];
		$email			= $_POST['email'];
		$username		= $_POST['username'];
		$password 		= $_POST['password'];
		$re_password	= $_POST['re_password'];

		if(empty($username) || empty($password) || empty($re_password)) {
			echo "<script>alert('Data yang diisi belum lengkap'); window.location = 'registered.php'</script>";
		}
		else {
			if($password == $re_password) {
				$query = mysqli_query($koneksi, "SELECT * FROM t_user WHERE username='$username'");
				$daftar = mysqli_num_rows($query);
				if($daftar == NULL){
					mysqli_query($koneksi, "INSERT INTO t_user VALUES('', '$role', '$username', '$password', '$nama_lengkap', '$email', '$alamat', '$nomor_ponsel')");
				echo "<script>alert('Daftar Berhasil $username, Silahkan masuk'); window.location = 'login.php';</script>";
				}
				else{
					echo "<script>alert('Nama pengguna sudah terdaftar!'); window.location = 'login.php'</script>";
				}
			}
			else{
				"<script>alert('Password tidak sama!'); window.location = 'registered.php'</script>";
			}
		}
	}
?>