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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.