purtip3154 Posted December 29, 2007 Share Posted December 29, 2007 Here's the part of the code that I've been having problems with: while (odbc_fetch_row($rs)) { $uname=odbc_result($rs,"Username"); $pword=odbc_result($rs,"Password"); if($_POST["user"] == $uname){ if($_POST["pass"] == $pword){ echo $b1.$hed1."<font color='aqua'>Correct login, what would you like to do next?:</font><br /><ul><li><a href='http://localhost/proj/addre.php'>Check Addresses</a></li><li><a href='http://localhost/proj'>Go Back!</a></li></ul>".$e1; break; }elseif ($_POST["user"] && $_POST["pass"]){ echo $b1.$hed1."<font color='red'><b>Invalid username and/or password!</b></font><br /><br />".$f1.$e1; break; } } } When you type in a correct username, and the incorrect password, it shows the invalid u/p message, but when you type in an incorrect username, and a correct or incorrect password, then it just shows a blank screen. Is there some way to do this that if you have the wrong username, it shows the error message too? Quote Link to comment https://forums.phpfreaks.com/topic/83596-solved-validation-problem/ Share on other sites More sharing options...
revraz Posted December 29, 2007 Share Posted December 29, 2007 Try this <?php while (odbc_fetch_row($rs)) { $uname=odbc_result($rs,"Username"); $pword=odbc_result($rs,"Password"); if($_POST["user"] == $uname && $_POST["pass"] == $pword){ echo $b1.$hed1."<font color='aqua'>Correct login, what would you like to do next?:</font><br /><ul><li><a href='http://localhost/proj/addre.php'>Check Addresses</a></li><li><a href='http://localhost/proj'>Go Back!</a></li></ul>".$e1; } else { echo $b1.$hed1."<font color='red'><b>Invalid username and/or password!</b></font><br /><br />".$f1.$e1; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/83596-solved-validation-problem/#findComment-425306 Share on other sites More sharing options...
naveenbj Posted December 29, 2007 Share Posted December 29, 2007 Hello try with this code .................................. while (odbc_fetch_row($rs)) { $uname=odbc_result($rs,"Username"); $pword=odbc_result($rs,"Password"); if($_POST["user"] == $uname && $_POST["pass"] == $pword){ echo $b1.$hed1."<font color='aqua'>Correct login, what would you like to do next?:</font><br /><ul><li><a href='http://localhost/proj/addre.php'>Check Addresses</a></li><li><a href='http://localhost/proj'>Go Back!</a></li></ul>".$e1; break; }elseif ($_POST["user"] && $_POST["pass"]){ echo $b1.$hed1."<font color='red'><b>Invalid username and/or password!</b></font><br /><br />".$f1.$e1; break; } } } i may think this will work Regards Quote Link to comment https://forums.phpfreaks.com/topic/83596-solved-validation-problem/#findComment-425307 Share on other sites More sharing options...
papaface Posted December 29, 2007 Share Posted December 29, 2007 Do: <?php while (odbc_fetch_row($rs)) { $uname=odbc_result($rs,"Username"); $pword=odbc_result($rs,"Password"); if($_POST["user"] == $uname) { if ($_POST["pass"] == $pword) { echo $b1.$hed1."<font color='aqua'>Correct login, what would you like to do next?:</font><br /><ul><li><a href='http://localhost/proj/addre.php'>Check Addresses</a></li><li><a href='http://localhost/proj'>Go Back!</a></li></ul>".$e1; } else { echo $b1.$hed1."<font color='red'><b>Invalid password!</b></font><br /><br />".$f1.$e1; } } else { echo $b1.$hed1."<font color='red'><b>Invalid username!</b></font><br /><br />".$f1.$e1; } } ?> Pretty simple stuff. Quote Link to comment https://forums.phpfreaks.com/topic/83596-solved-validation-problem/#findComment-425310 Share on other sites More sharing options...
naveenbj Posted December 29, 2007 Share Posted December 29, 2007 Sry try this code while (odbc_fetch_row($rs)) { $uname=odbc_result($rs,"Username"); $pword=odbc_result($rs,"Password"); if($_POST["user"] == $uname && $_POST["pass"] == $pword){ echo $b1.$hed1."<font color='aqua'>Correct login, what would you like to do next?:</font><br /><ul><li><a href='http://localhost/proj/addre.php'>Check Addresses</a></li><li><a href='http://localhost/proj'>Go Back!</a></li></ul>".$e1; break; }elseif ($_POST["user"] && $_POST["pass"]){ echo $b1.$hed1."<font color='red'><b>Invalid username and/or password!</b></font><br /><br />".$f1.$e1; break; } } } Quote Link to comment https://forums.phpfreaks.com/topic/83596-solved-validation-problem/#findComment-425311 Share on other sites More sharing options...
purtip3154 Posted December 29, 2007 Author Share Posted December 29, 2007 Thanks for all the help, but I've tried variations of those codes, what they do is repeat the error message and form until they find the right u/p in the database, which could be a lot of repeats. Quote Link to comment https://forums.phpfreaks.com/topic/83596-solved-validation-problem/#findComment-425313 Share on other sites More sharing options...
papaface Posted December 29, 2007 Share Posted December 29, 2007 Well thats because your SQL isn't correct. e.g (part of my class) function LoginCheckUsername($username) { if ($username != "" || $username != " ") { $check = mysql_query('SELECT `username` FROM `members` WHERE `username`="'.$username.'"'); if (mysql_num_rows($check) == 1) { $this->username = $username; return true; } else return false; } else return false; } ^^ Thats the right way to do it. Quote Link to comment https://forums.phpfreaks.com/topic/83596-solved-validation-problem/#findComment-425316 Share on other sites More sharing options...
purtip3154 Posted December 29, 2007 Author Share Posted December 29, 2007 What is the equivalent of mysql_check_rows() using odbc? Quote Link to comment https://forums.phpfreaks.com/topic/83596-solved-validation-problem/#findComment-425321 Share on other sites More sharing options...
papaface Posted December 29, 2007 Share Posted December 29, 2007 http://uk.php.net/manual/en/function.odbc-num-rows.php odbc_num_rows() .... Quote Link to comment https://forums.phpfreaks.com/topic/83596-solved-validation-problem/#findComment-425330 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.