<?php
include "settings.php";
?>
<html>
<head>
<title>Login System</title>
<style type="text/css">
#container
{
position: relative;
width: 500px;
margin: 0px auto;
height: auto;
background-color: #ddd;
border: 1px solid #666;
padding: 15px;
}
.o
{
background-color: #f0f0f0;
padding: 4px;
}
</style>
</head>
<body>
<div id='container'>
<h2>Welcome to Login System</h2>
<hr />
<div id='frmSignIn' class='o'>
<h3>Login</h3>
<form action = 'index.php' method = 'post'>
Email: <input type = 'text' name = 'email' ><br>
Password: <input type = 'password' name = 'pass' ><br>
<input type='submit' value= 'signin' name = 'signIn'>
</form>
<div 'form-result'>
<?php
if(isset($_POST['signIn']))
{
$email = $_POST['email'];
$pass = $_POST['pass'];
if(!$email || !$pass)
{
echo "<p style='color:red'>Please enter all values</p>";
}
else
{
$sql = "SELECT * FROM users WHERE email = '$email' AND password = '$pass'";
//echo $sql ; exit;
$q = mysql_query($sql);
if($q)
{
$data = mysql_fetch_assoc($q);
if(!empty($data))
{
$_SESSION['user'] = $data;
header("Location: user.php");
}
else
{
echo "<p style='color:red'>Your email and password combination are not correct.</p>";
}
}
else
{
echo "Errro in database";
}
}
}
?>
</div>
</div>
<hr />
<h3>Sign up</h3>
<div id='frmSignUp' class='o'>
<form action = '' method = 'post' name=''>
Username: <input type = 'text' name = 'username' ><br>
Email: <input type = 'text' name = 'email' ><br>
Password: <input type = 'password' name = 'password' ><br>
<input type='submit' value= 'signUp' name = 'signUp'>
</form>
<div>
<?php
if(isset($_POST['signUp']))
{
$email = $_POST['email'];
$pass = $_POST['password'];
$username = $_POST['username'];
if(!$email || !$pass || !$username)
echo "Please enter all the values to sign up";
else
{
$sql = "INSERT INTO users VALUES ('', '$username','$email','$pass')";
$query = mysql_query($sql);
if($query)
echo "Registered successfully";
else
echo "Failed. There was an error while registering you.";
}
}
?>
</div>
</div>
<hr />
</div>
</body>
</html>
0 comments:
Post a Comment