Jump to content

testing users logging in ----- whats wrong with my code


Recommended Posts

the code below keeps outputting "login unsuccessful" even if I enter the correct username and password.  Where am I going wrong?  Sorry I am a newbie in PHP.  Thanks for helping me.

 

<?php

$username=$_POST['username'];
$password=$_POST['password'];

if ($username && $password) {

     $db = odbc_connect("xx","xxx","xxx") or die ("xxxxx");
     
      $sql = "SELECT * FROM logintest WHERE username='$username' AND password='$password'";
      $res = odbc_exec($db, $sql);
      $row = odbc_fetch_array($res);
     
         
      if(($username && $password) == ($row['username'] && $row['password'])) {
        
        echo "login successful";
        } else {
        echo "login unsuccessful";
        }
}
   odbc_free_result($res);

odbc_close($db);

?>       

try changing it to this...

<?php

$username = $_POST['username'];
$password = $_POST['password']; // if the password is hashed in the database then hash this input md5($_POST['password']);

if (isset(!empty($username)) && isset(!empty($password))) {

     $db = odbc_connect("xx","xxx","xxx") or die ("xxxxx");
     
      $sql = "SELECT * FROM logintest WHERE username='$username' AND password='$password'";
      $res = odbc_exec($db, $sql);
      $row = odbc_fetch_array($res);
     
         
      if($username == $row['username'] && $password == $row['password']) 
        {
        echo "login successful";
        } else {
        echo "login unsuccessful";
        }
}
   odbc_free_result($res);

odbc_close($db);

?>  

 

Regards, ACE

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.