Jump to content

login function problem


keepAway

Recommended Posts

I can not handle with this function, will allways return 0  mysql_num_rows and i`m not able to login.

 

<?php 
session_start();
mysql_connect("localhost", "root", ""); 
mysql_select_db("proiect");
include("inc/functii.php");


echo "<form method='post' name='login'>
      <table cellspacing='1' cellpadding='2' border='0' >
        <tr>
	  <td colspan='2' align='center' height='55'> Admin Login </td>
	</tr>  
	<tr>
	  <td id='paddingbot' colspan='2'> Username </td>
	</tr>
	<tr>
	  <td id='paddingtop' colspan='2'><input type='text' name='username' size='33'/></td>
        </tr>
	<tr>
	  <td colspan='2'></td>
	</tr>
        <tr>
          <td id='paddingbot' colspan='2'> Password </td>
	</tr>		
        <tr>
	  <td id='paddingtop' colspan='2'><input type='password' name='password' size='33' /></td>
	</tr>
	<tr>
	  <td id='rem_me'><input type='checkbox' name='remember_me' /></td> <td> Remember me </td>
        </tr>
        <tr>
	  <td align='right' colspan='2'><input type='submit' name='login' value='Login >' /></td>
        </tr>
	<tr>
	  <td colspan='2' align='center'>"; checkLogin(); 
echo  "</tr>
  </table>
     </form>";





?>

<?php
function checkLogin () {

if (isset($_POST['login']))
    if (($_POST['username']) == '')
   {
   echo "Please, complete the field for username.";
   } elseif (($_POST['password']) == '') 
            {
            echo "Please, complete the field for password.";
			} elseif (($_POST['username'] !== '') && ($_POST['password']) !== '')
			         {
					 $username = $_POST['username'];
					 $password = md5($_POST['password']);
					 $result = mysql_query("SELECT * FROM admin WHERE username='".$username."' AND password='".$password."'") or die ("Error:".mysql_error());
					 $nr = mysql_num_rows($result);
					 if ($nr < 1)
					    {
						echo $nr;
					    } else {
                              $_SESSION['username'] = $username;
                              $_SESSION['password'] = $password;
                              echo "Welcome".$username;
                                   }
					 }
                         
				  }




?>

Link to comment
https://forums.phpfreaks.com/topic/237136-login-function-problem/
Share on other sites

Are the passwords in your database stored as md5 hashes. Also make sure the password field is set to at lease 32 characters. md5() will return a 32 character hash, if the password field does not store enough characters the query will always fail.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.