<?php
	session_start();
	session_destroy();
include'connect_db.php';
 
	
	$username=$_POST['username'];
	$pass=$_POST['password'];
	$name=$_POST['name'];
	$age=$_POST['Age'];
	$email=$_POST['email'];
	$city=$_POST['city'];

	
	$password=md5($pass);
	$C_password=$_POST['C_password'];
	
if(isset($_POST['btnsubmit']))
{
/* Now we will check if username is already in use or not */
	$query=mysql_query("SELECT * FROM user WHERE Username='$username' ");
	$count=mysql_num_rows($query);
	if($count != 0)
	{ 
		echo "Sorry, ".$username." is already been taken.";
	}
	else 
	{
 
/* now we will check if password and confirm password matched */
	if($pass != $C_password)
	{ 
		echo "<script language='javascript'>
		alert('Password and confirm password fields were not matche') 
		
		</script>";
	}
	else 
	{
 
/* Now we will write a query to insert user details into database */
	$insert_user=mysql_query("INSERT INTO user (Name, Age, Email, City, Username, Password) 
	VALUES ('$name', '$age', '$email', '$city','$username', '$password')");
 
		if($insert_user)
		{ 
			echo "<script language='javascript'>
		alert('Registration Succesfull!!'),window.location ='index.php';
		
		</script>";
		
		
		}
		else
		{ 
			echo "error in registration".mysql_error();
		}

	}
	}
}
	mysql_close($link);

?>


