worldcomingtoanend Posted March 18, 2009 Share Posted March 18, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/149958-whats-wrong-with-my-php-login-script-please-help/ Share on other sites More sharing options...
btherl Posted March 18, 2009 Share Posted March 18, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/149958-whats-wrong-with-my-php-login-script-please-help/#findComment-787562 Share on other sites More sharing options...
Adam Posted March 18, 2009 Share Posted March 18, 2009 Could also try: $result=odbc_exec($db,$query) or die(odbc_error()); Adam Quote Link to comment https://forums.phpfreaks.com/topic/149958-whats-wrong-with-my-php-login-script-please-help/#findComment-787565 Share on other sites More sharing options...
tbare Posted March 18, 2009 Share Posted March 18, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/149958-whats-wrong-with-my-php-login-script-please-help/#findComment-787575 Share on other sites More sharing options...
syed Posted March 18, 2009 Share Posted March 18, 2009 odbc_num_rows will sometimes return -1 depending on driver version. Check if this is the case by printing $num_rows variable. Quote Link to comment https://forums.phpfreaks.com/topic/149958-whats-wrong-with-my-php-login-script-please-help/#findComment-787586 Share on other sites More sharing options...
worldcomingtoanend Posted March 18, 2009 Author Share Posted March 18, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/149958-whats-wrong-with-my-php-login-script-please-help/#findComment-787599 Share on other sites More sharing options...
syed Posted March 18, 2009 Share Posted March 18, 2009 So you have a -1 returned? ->> 'trance'-1welcome Quote Link to comment https://forums.phpfreaks.com/topic/149958-whats-wrong-with-my-php-login-script-please-help/#findComment-787604 Share on other sites More sharing options...
worldcomingtoanend Posted March 18, 2009 Author Share Posted March 18, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/149958-whats-wrong-with-my-php-login-script-please-help/#findComment-787607 Share on other sites More sharing options...
worldcomingtoanend Posted March 18, 2009 Author Share Posted March 18, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/149958-whats-wrong-with-my-php-login-script-please-help/#findComment-787608 Share on other sites More sharing options...
syed Posted March 18, 2009 Share Posted March 18, 2009 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"; } Quote Link to comment https://forums.phpfreaks.com/topic/149958-whats-wrong-with-my-php-login-script-please-help/#findComment-787635 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.