worldcomingtoanend Posted March 20, 2009 Share Posted March 20, 2009 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); ?> Link to comment https://forums.phpfreaks.com/topic/150295-testing-users-logging-in-whats-wrong-with-my-code/ Share on other sites More sharing options...
Festy Posted March 20, 2009 Share Posted March 20, 2009 Change your if statement as: if(($username == $row[username]) && ($password == $row[password])) Link to comment https://forums.phpfreaks.com/topic/150295-testing-users-logging-in-whats-wrong-with-my-code/#findComment-789281 Share on other sites More sharing options...
MasterACE14 Posted March 20, 2009 Share Posted March 20, 2009 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 Link to comment https://forums.phpfreaks.com/topic/150295-testing-users-logging-in-whats-wrong-with-my-code/#findComment-789285 Share on other sites More sharing options...
worldcomingtoanend Posted March 20, 2009 Author Share Posted March 20, 2009 i hv tried the above from ACE and Festy but its still displaying the same result. Link to comment https://forums.phpfreaks.com/topic/150295-testing-users-logging-in-whats-wrong-with-my-code/#findComment-789300 Share on other sites More sharing options...
worldcomingtoanend Posted March 20, 2009 Author Share Posted March 20, 2009 Now i have echoed my variables $res and $num_rows and I get the following output login unsuccessful, Resource id #3, 0 Link to comment https://forums.phpfreaks.com/topic/150295-testing-users-logging-in-whats-wrong-with-my-code/#findComment-789349 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.