XiledWeb
12-30-2006, 08:43 PM
I'm going to refer to my thread yesterday (http://www.codingforums.com/showthread.php?t=103956) about developing a registration system for users logging in.
This morning I've been working on a login script.
My login form is as follows:
<form name="form1" method="post" action="checklogin.php">
<p>Please Enter Your
<label>Username: <input name="myusername" type="text" id="myusername" /></label> <label>Email: <input name="myemail" type="text" id="myemail" /></label> <label>Password: <input name="mypassword" type="password" id="mypassword" /></label><input type="submit" name="Submit" value="login" /></form>
My checklogin.php code is:
<?php
include 'db.inc.php';
$tbl_name="members"; // Table name
// username and password sent from signup form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$myemail=$_POST['myemail'];
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword' and email='$myemail'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword and $myemail, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword, $myemail and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
session_register("myemail");
header("Location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>
and finally, my login_success.php is
// Check if session is not registered , redirect back to main page.
// Put this code in first line of web page.
<?
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
?>
<html>
<body>
Login Successful
</body>
</html>
When I click on 'login' I'm getting the error that is being echoed in my checklogin.php code:
"Wrong username and password"
This morning I've been working on a login script.
My login form is as follows:
<form name="form1" method="post" action="checklogin.php">
<p>Please Enter Your
<label>Username: <input name="myusername" type="text" id="myusername" /></label> <label>Email: <input name="myemail" type="text" id="myemail" /></label> <label>Password: <input name="mypassword" type="password" id="mypassword" /></label><input type="submit" name="Submit" value="login" /></form>
My checklogin.php code is:
<?php
include 'db.inc.php';
$tbl_name="members"; // Table name
// username and password sent from signup form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$myemail=$_POST['myemail'];
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword' and email='$myemail'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword and $myemail, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword, $myemail and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
session_register("myemail");
header("Location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>
and finally, my login_success.php is
// Check if session is not registered , redirect back to main page.
// Put this code in first line of web page.
<?
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
?>
<html>
<body>
Login Successful
</body>
</html>
When I click on 'login' I'm getting the error that is being echoed in my checklogin.php code:
"Wrong username and password"