Create member LOG IN after SIGN UP
<?php
$dbuser = "root";
$dbpw = "";
$db = "cp1";
$host = "localhost";
$conn = mysql_connect($host, $dbuser, $dbpw) or die ("Unable to connected to the database: ".mysql_error());
mysql_select_db($db) or die ("Unable to select the database: ".mysql_error());
?>
db.php
------------------------------------------------------
<?php
session_start();
$error1 = "";
$msg = "";
$un = "";
$pw = "";
$email = "";
$err_un = "";
$err_pw = "";
$err_e = "";
function isEmpty($val)
{
if(strlen($val) == 0)
{
return true;
}
else
{
return false;
}
}
if(isset($_POST['btnSubmit'])){
$error1 = 0;
$un = $_POST['txtun'];
$pw = $_POST['txtpw'];
$email = $_POST['txtemail'];
if(isEmpty($un)){
$error1 = 1;
$err_un = "*Required Feild!";
}
if(isEmpty($pw)){
$error1 = 1;
$err_pw = "*Required Feild!";
}
if(isEmpty($email)){
$error1 = 1;
$err_e = "*Required Feild!";
}
if($error1 == 0){
$count = 0;
include "db.php";
$sql = "INSERT INTO MEMBER(username, password, email) VALUES('$un', md5('$pw'), '$email')";
mysql_query($sql) or die(mysql_error());
$count = mysql_affected_rows($conn);
if($count > 0){
$msg = "Submitted your data into the DB!";
}
else{
$msg = "Record not saved!";
}
}
}
?>
<html>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
Name: <input type="text" name="txtun">
<?php echo $err_un; ?><br>
Password: <input type="password" name="txtpw"> <?php echo $err_pw; ?><br>
Email: <input type="text" name="txtemail"> <?php echo $err_e; ?><br>
<input type="submit" name="btnSubmit" value="Submit"> <?php echo $msg; ?><br>
<input type="reset" value="Reset" onClick="history.go(0)">
</form>
<br>
<a href="login.php">Login</a>
</body>
</html>
signup.php
----------------------------------
<?php
session_start();
$_SESSION=array();
if(isset($_COOKIE[session_name()]))
{
setcookie(session_name(),"",time()-4200,"/");
}
header("Location:signup.php");
session_destroy();
?>
logout.php
-------------------------
<?php
$error="";
if(isset($_POST['btnLogin']) and $_POST['btnLogin']="Login")
{
//Process login
$un=$_POST['txtun'];
$pw=$_POST['txtpw'];
include "db.php";
$sql="select * from member where username='$un' and password=md5('$pw')";
$results=mysql_query($sql) or die("Error on application: ".mysql_error());
$rowcount= mysql_num_rows($results);
if($rowcount>0)
{
//User Available
session_start();
$_SESSION['user']=$user;
header("Location:ok.php");
}
else
{
//Invalied User
$error="<font size=1 color=red>Invalied User name or Password</font>";
}
}
?>
<html>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
Username: <input type="text" name="txtun"><br>
Password: <input type="text" name="txtpw"><br>
<input type="submit" value="Login" name="btnLogin"><br>
<input type="reset" value="Refresh" onClick="history.go(0)">
<?php echo $error;?>
</form>
</body>
</html>
login.php
$dbuser = "root";
$dbpw = "";
$db = "cp1";
$host = "localhost";
$conn = mysql_connect($host, $dbuser, $dbpw) or die ("Unable to connected to the database: ".mysql_error());
mysql_select_db($db) or die ("Unable to select the database: ".mysql_error());
?>
db.php
------------------------------------------------------
<?php
session_start();
$error1 = "";
$msg = "";
$un = "";
$pw = "";
$email = "";
$err_un = "";
$err_pw = "";
$err_e = "";
function isEmpty($val)
{
if(strlen($val) == 0)
{
return true;
}
else
{
return false;
}
}
if(isset($_POST['btnSubmit'])){
$error1 = 0;
$un = $_POST['txtun'];
$pw = $_POST['txtpw'];
$email = $_POST['txtemail'];
if(isEmpty($un)){
$error1 = 1;
$err_un = "*Required Feild!";
}
if(isEmpty($pw)){
$error1 = 1;
$err_pw = "*Required Feild!";
}
if(isEmpty($email)){
$error1 = 1;
$err_e = "*Required Feild!";
}
if($error1 == 0){
$count = 0;
include "db.php";
$sql = "INSERT INTO MEMBER(username, password, email) VALUES('$un', md5('$pw'), '$email')";
mysql_query($sql) or die(mysql_error());
$count = mysql_affected_rows($conn);
if($count > 0){
$msg = "Submitted your data into the DB!";
}
else{
$msg = "Record not saved!";
}
}
}
?>
<html>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
Name: <input type="text" name="txtun">
<?php echo $err_un; ?><br>
Password: <input type="password" name="txtpw"> <?php echo $err_pw; ?><br>
Email: <input type="text" name="txtemail"> <?php echo $err_e; ?><br>
<input type="submit" name="btnSubmit" value="Submit"> <?php echo $msg; ?><br>
<input type="reset" value="Reset" onClick="history.go(0)">
</form>
<br>
<a href="login.php">Login</a>
</body>
</html>
signup.php
----------------------------------
<?php
session_start();
$_SESSION=array();
if(isset($_COOKIE[session_name()]))
{
setcookie(session_name(),"",time()-4200,"/");
}
header("Location:signup.php");
session_destroy();
?>
logout.php
-------------------------
<?php
$error="";
if(isset($_POST['btnLogin']) and $_POST['btnLogin']="Login")
{
//Process login
$un=$_POST['txtun'];
$pw=$_POST['txtpw'];
include "db.php";
$sql="select * from member where username='$un' and password=md5('$pw')";
$results=mysql_query($sql) or die("Error on application: ".mysql_error());
$rowcount= mysql_num_rows($results);
if($rowcount>0)
{
//User Available
session_start();
$_SESSION['user']=$user;
header("Location:ok.php");
}
else
{
//Invalied User
$error="<font size=1 color=red>Invalied User name or Password</font>";
}
}
?>
<html>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
Username: <input type="text" name="txtun"><br>
Password: <input type="text" name="txtpw"><br>
<input type="submit" value="Login" name="btnLogin"><br>
<input type="reset" value="Refresh" onClick="history.go(0)">
<?php echo $error;?>
</form>
</body>
</html>
login.php
Post a Comment