<?php
	session_start();
	session_destroy();
	$link=mysql_connect("localhost", "root")
	or die("could not connect to database server");
	mysql_select_db("ramones", $link) or die(mysql_error());
	
	$username=$_POST['username'];
	$pass=$_POST['password'];
	$Fname=$_POST['Fname'];
	$Lname=$_POST['Lname'];
	$email=$_POST['email'];
	$age=$_POST['Age'];
	$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 (Firstname, Lastname, Email, Age, Username, Password) 
	VALUES ('$Fname', '$Lname', '$email', '$age','$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);

?>


<html>
<title> Ramones </title>
<head>
<link rel="stylesheet" type="text/css" href="default.css" />
<script type="text/javascript">
function myfunction()
{
	window.location ='login.php';
}
</script>
</head>
<body>

<div id="wrapper">

<div id="container">
	

	<div id="content">
		
		<div style="margin: 40px auto 40px auto;
width: 585px;
background:black;
height: 550px;
border-radius: 10px;
padding-left: 10px;
padding-right: 10px;
padding-bottom: 10px;
color:white;
">

<h1 style=" color:white;">  Registration </h1>

<br/>
		<div
		style="color: #666;line-height:60px;padding: 10px 40px 10px 40px;
		font-weight:bold;font-size:20px;margin-top:20px;margin-bottom:40px;">
		
		<form action="register.php" method="Post">
			Firtsname : <input type="text" size="50" maxlength="50" name="Fname"><br/>
			Lastname : <input type="text" size="50" maxlength="50" name="Lname"><br/>
			E-mail &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: <input type="text" size="50" maxlength="50" name="email"><br/>
			Age &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : <input type="text" size="50" maxlength="50" name="Age"><br/>
			Username : <input type="text" size="50" maxlength="50" name="username"><br/>
			Password &nbsp;:  <input type="password" size="50" maxlength="50" name="password"><br/>
			Confirm Password: 
						<input type="password" size="40" maxlength="50" name="C_password"><br/>
			<input type="submit"name="btnsubmit" value="Submit" 
			style="width:100px; height:25px; background-color:rgb(178,178,178); 
			font-weight:bold;font-size:15px;border-raduis:10px; font-family: arial, sans serif;
			color:black; margin: 0 30px; 0 30px; 0 30px;">
			<input type="reset"  value="Clear All" 
			style="width:100px; height:25px; background-color:rgb(178,178,178); 
			font-weight:bold;font-size:15px;border-raduis:10px; color:black;">
			
			<input type="button" name="buttonback" value="Back" onclick="myfunction()"
			style="width:100px; height:25px; background-color:rgb(178,178,178); 
			font-weight:bold;font-size:15px;border-raduis:10px; color:black;
			margin-left:30px;" >
		</form>
		<div>
			
				<div class="clear"></div>
				
					
		</div>

	</div>

<div  class="clear"></div>

</div>
</div>

</body>

</html>