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);

?>

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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";

}

Link to comment
Share on other sites

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.