Jump to content

user login, user not found


rafal

Recommended Posts

Hallo everybody,

i have the following code.

but i get allways this error while the user exist in the database.

User not found!

what do i do wrong?

 

thank you very much for your help

Rafal

<html>
<head>
<?php
$connection = mysql_connect("db.xyz.com", "username", "password")
or die ("connection fehler");
mysql_select_db("db0123456789")
or die ("database fehler");
$email = $_POST["inp_email"];
$pwd = $_POST["inp_pwd"];
if($email && $pwd)
{
$chkuser = mysql_query("SELECT email FROM gbook WHERE email = '($email)' ");
$chkuserare = mysql_num_rows($chkuser);
echo $email;
echo $pwd;
if ($chkuserare !=0)
{
$chkpwd = mysql_query("SELECT pwd FROM gbook WHERE email = '($email)' ");
$pwddb = mysql_fetch_assoc($chkpwd);
if ($pwd != $pwddb["pwd"])
{
echo "password is wrong!";
}
else
{
echo "login successed";
}
}
else
{
echo "User not found!";
}
}
else
{
echo "Pleas enter your email and password!";
}
mysql_close($connection);
?>
</head>
<body>
<form action="login.php" method="post">
Email <input type="text" name="inp_email"><br>
Password <input type="text" name="inp_pwd"><br>
<input type="submit" name="submit" value="login">
</form>
</body>
</html>
Edited by rafal
Link to comment
Share on other sites

Why do you wrap your query args in parentheses?  Are you really seeking an email of (me @ domain . com)  or do you want me @ domain . com?

(Spaces added by me)

 

And why do you do two queries?  This s/b all done with one query. 

 

And you should be using some kind of security to scramble your password and not be storing it in your db un-scrambled.

 

Plus - why make your db connection before you are sure to need it?

 

Plus - you should really check the query results before fetching a row - there might not be any rows there if the query fails.(You should always verify that the query ran before checking for row count or fetching results)

Link to comment
Share on other sites

dear gingerjm,

thank you very much for your help,

i did some changes.

i show you my result.

is it now ok, or still i have errors?

 

thanks

Rafal

<html>
<head>
<?php
SESSION_START();
$connection = mysql_connect("db.xyz.com", "username", "password")
or die ("connection error");
mysql_select_db("database")
or die ("database error");
$email = $_POST["inp_email"];
$pwd = $_POST["inp_pwd"];
if($email && $pwd)
{
$chkuser = mysql_query("SELECT email FROM gbook WHERE email = '$email' ");
$chkuserare = mysql_num_rows($chkuser);
if ($chkuserare !=0)
{
$chkpwd = mysql_query("SELECT pwd FROM gbook WHERE email = '$email'");
$pwddb = mysql_fetch_assoc($chkpwd);
if (md5($pwd) != $pwddb["pwd"])
{
echo "Password is wrong!";
}
else
{
echo "login successed";
$_SESSION['username'] = $email;
header ('Location:list.php');
}
}
else
{
echo "user not found!";
}
}
else
{
echo "enter Email and Password!";
}
mysql_close($connection);
?>
</head>
<body style="font-family: arial;margin: 10; padding: 0" bgcolor="silver">
<font color="black">
<br>
<form action="login.php" method="post">
<b>Login</b><br><br>
<table>
<tr><td>
Email:<br><input type="text" name="inp_email"><br>
Password:<br><input type="text" name="inp_pwd"><br>
<br>
<input type="submit" name="submit" value="login">
</td></tr>
</table>
</form>
</font>
</body>
</html>
Link to comment
Share on other sites

Perhaps you already got this figured out, but mysql_fetch_assoc() returns the next row in the result set...otherwise it returns false. So basically your first query could be dropped altogether. You can do something like this instead:

$result = mysql_query("SELECT pwd FROM gbook WHERE email = '$email' ");
if($row = mysql_fetch_assoc($result))
{
     if(md5($pwd) != $row['pwd'])
     {
          //...

You'll also want to check out the mysql_real_escape_string() function to help protect your database from SQL injection attacks. More information can be found here:

http://php.net/manual/en/function.mysql-real-escape-string.php

 

 

Side note:
In case you're not aware, md5() should not be used for hashing passwords. More information can be found in the PHP manual:
  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.