<?php
include ("includes/database.php");
?>

<!DOCTYPE html>
<html>
<head>
<!-- youtube.com /DarkCode -->
	<meta charset="utf-8">
	<title>REGISTER FORM</title>
	<link rel="stylesheet" type="text/css" href="style2log.css">

<title>REGISTRATION</title>

<?php
if (!(isset($_POST["name"])))
{
?>
<body>
<form method="post" enctype="multipart/form-data">
	
<center>


<label>Full Name</label>
<input class="form-control" placeholder="Name" name="name" type="text" required autocomplete"on"><br>
<br>
<label>Username</label>
<input class="form-control" placeholder="Username" name="username" type="text" required autocomplete"on"><br>
<br>
<label>Password</label>
<input class="form-control" placeholder="eg:1234" name="password" type="password" required autocomplete"on"><br>
<br>
<label>Address</label>
<input class="form-control" placeholder="eg:Machang, Kelantan" name="add" type="text" required autocomplete"on"><br>
<br>
<label>Phone Number</label>
<input class="form-control" placeholder="eg:01********" name="phone" type="tel" required autocomplete"on"><br>
<br>
<label>Email</label>
<input class="form-control" placeholder="eg:123@gmail.com" name="email" type="email" required autocomplete"on"><br>
<br>
<input class="form-control" name="photo" type="file"><br>

<input type="submit" name="submit" value="register"><br>
</form>
<br>
<a class="nav-link js-scroll-trigger" href="index.php">Already a member? LOG IN here</a>
</center>
</form>
</body>

<?php
}
else
{

//get data
$user=$_POST["name"];
$name=$_POST["username"];
$add1=$_POST["add"];
$phone=$_POST["phone"];
$email=$_POST["email"];
$pwd=$_POST["password"];

//check duplicate
$data=mysqli_query($con, "SELECT * from tbl_user where username ='$user'");
$wujud=mysqli_num_rows($data);

if ($wujud>0)
{echo "Username already taken. <a href='register.php'>Try again</a>.";}
else
{

$namaFile=$user.$_FILES["photo"]["name"];

//upload picture
move_uploaded_file($_FILES["photo"]["tmp_name"],"user/".$namaFile);



mysqli_query($con,"insert into tbl_user(user_name, username,user_password, user_address, user_phone, user_email, user_photo) values ('$user','$name', '$pwd','$add1','$phone','$email','$namaFile')") or die (mysqli_error($con));

echo "New record inserted. Click <a href='index.php'>here</a> to login";



}
}

?>
</center>

</body>
</html>