Jump to content

Newbie problem with echo


nelsonsix

Recommended Posts

Hi,

 

Im pretty new to php but im have trouble understanding why my script is doing this. Forgive me for silly mistakes!

 

Im creating a login/register website and once the person has logged in they get a message saying "Successful login, welcome username!"

 

The php checks against a database of users in an if statement to check if the password is correct and then prints out the message. But at the end of the message the echo is printing out a 1.

 

I get that because the echo is in an if statement its return true or 1 but I cant get it to not print out the 1.

 

code snippet is -

 

 

if ($username==$dbusername&&$password==$dbpassword)

{

echo "Successful login, welcome!";

}

 

 

Hope that makes sense.

 

Thanks for the help.

Neil

Link to comment
https://forums.phpfreaks.com/topic/253222-newbie-problem-with-echo/
Share on other sites

try adding

 

else
{
    echo " username, password or both not found";
}

 

so your if statement reads

if ($username==$dbusername&&$password==$dbpassword)
{
echo "Successful login, welcome!";
}
else
{
    echo " username, password or both not found";
}

 

at least you'll know if its even checking that if statement, the else bit is executed if the"if" is false, and you get either a welcome msg or a not found msg .

Without seeing more code, just do the following to make sure you are getting the right values in each variable:

 

echo $username;
echo '<br />';
echo $password;

 

Once you confirm the values are right, then dig into your if statement.  something like:

 

if ( ($username==$dbusername) && ($password==$dbpassword) )
{
    echo 'Im Here';
}

 

If you see Im Here on your page, you know you are inside the if statement and on the right track.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.