Jump to content

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.

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.