View Single Post
Old 10-10-2012, 06:55 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,395
Thanks: 18
Thanked 351 Times in 350 Posts
sunfighter is on a distinguished road
I can't get this to malfunction. Your php echos zero if your query works. Almost fool proof. But may I suggest some changes:
You are not encoding the $password, you should.
your query asks for everything done by the use of * and you don't need everything, you just need email! so make this change:
Code:
 $sql=mysql_query("select email from register1 where username='$username' AND password='$password'");
I really hate the if statement of mysql_num_rows($sql)>0 You will get this even if you have two or more querys that meet the curriculum, that means double entree.
Use:
Code:
if(mysql_num_rows($sql) == 1)
That will eliminate the need for the while loop replace it with:
Code:
$info=mysql_fetch_assoc($sql);
You don't need the $username = $info['username']; line because you already have $username.

Now the echo "0"; This is just MHO but I like something more substantial like echo "correct"; and use an else statement to echo "incorrect credential";

for your html ajax return Id change things to:
Code:
if(result == "correct")
{
  $(document.location = "members.php");
}else
{
  $(".errors").html("incorrect credential");
}
Loginpost.php:
PHP Code:
<?php
include_once "conndb1.php";
if(
$_POST)
{
$username = ($_REQUEST['username']);
$password = ($_REQUEST['password']);  // use encode of your choice here
$sql=mysql_query("select email from register1 where username='$username' AND password='$password'");
if(
mysql_num_rows($sql) == 1)
{
  echo 
"correct";
  
$info mysql_fetch_assoc($sql);
  
$email $info["email"];
  
$expire=time()+ 86400;
  
setcookie("username",$username,$expire);
  
setcookie("email",$email,$expire);
}else{
  echo 
"incorrect credential";
}
?>
PS. Make sure the db is connected.

Last edited by sunfighter; 10-10-2012 at 07:10 PM..
sunfighter is offline   Reply With Quote