Jump to content

whats wrong with my PHP login script -- Please help


Recommended Posts

my code below connects sucessfully to my database using ODBC. I hv also managed to add users but when I try to enter the login details my script below simply keeps silent.  Where  am I getting it wrong.  Thanks for your help

 

<?php
$username=$_POST['username'];
$password=$_POST['password'];

$db = odbc_connect("xx","xx_user","xxx") or die ("xxx");
  

if($username && $password)
    {
    $query ="SELECT * FROM logintest WHERE username = '$username' AND password = '$password'";
    $result=odbc_exec($db,$query);
    $num_rows = odbc_num_rows($result);
        
if ($num_rows > 0)

{
print "welcome";
} else{
print "incorrect";
}
}

  
odbc_free_result($result);

odbc_close($db);

?>

 

 

 

Does it print nothing at all?  THere's two possibilities there:

 

1.  There's a fatal error and display_errors is switched off

2.  $username or $password is not set, and the query is never executed.

 

What I would do is add "echo $query" after you set $query, to check that the query looks ok.

i'm going to have to agree w/ btherl... it seems to me that $username and $password are not set... try echoing both of those right after you set them.

 

i might try this:

if(isset($_POST['username']))
     {
     $username = $_POST['username'];
     echo $username."<br/>";
     }
if(isset($_POST['password']))
     {
     $password = $_POST['password'];
     echo $password."<br/>";
     }

 

then lower use

 

if(isset($username) && isset($password))
      {
      //code here
      }

 

and see if you get anything different... this will tell you if the error is in the post at least

After implementing your suggestions I got the following output:

 

SELECT * FROM logintest WHERE username = 'techno' AND password = 'trance'-1welcome

The output above came out after I echoed $query and $num_rows. 

odbc_num_rows will sometimes return -1 depending on driver version. Check if this is the case by printing $num_rows variable.

yes but its not the end result i am anticipating.  It gives me that same output even if I use any usernames, passwords that I did not add to the database.  Besides this is a script that should test the entered username and password then grants or denies access.

 

So you have a -1 returned? ->> 'trance'-1welcome

yes but its not the end result i am anticipating.  It gives me that same output even if I use any usernames, passwords that I did not add to the database.  Besides this is a script that should test the entered username and password then grants or denies access.

 

So you have a -1 returned? ->> 'trance'-1welcome

Yes I know, it doesn't matter what username, password combination you do. You will still get -1 from the odbc_num_rows function.

 

If its the case that your script still does not seem to produce anything, then that in it self is a separate issue, if not the original issue.

 

First determine that your script contains the form data

 

print_r($_POST);

 

if ((isset($username) AND (isset($password))){

 

print "is set";

}

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.