Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/83596-solved-validation-problem/
Share on other sites

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;

}
}

?>

 

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

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.

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;

}

}

}

 

 

 

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.

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.