nelsonsix Posted December 15, 2011 Share Posted December 15, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/253222-newbie-problem-with-echo/ Share on other sites More sharing options...
SergeiSS Posted December 15, 2011 Share Posted December 15, 2011 You'd better show more code. The error is somewhere in another part of your code. Quote Link to comment https://forums.phpfreaks.com/topic/253222-newbie-problem-with-echo/#findComment-1298113 Share on other sites More sharing options...
AyKay47 Posted December 15, 2011 Share Posted December 15, 2011 there is more than likely output somewhere else in your code, nothing is wrong with your echo statement, please post the relevant code. Quote Link to comment https://forums.phpfreaks.com/topic/253222-newbie-problem-with-echo/#findComment-1298116 Share on other sites More sharing options...
jaisol Posted December 15, 2011 Share Posted December 15, 2011 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 . Quote Link to comment https://forums.phpfreaks.com/topic/253222-newbie-problem-with-echo/#findComment-1298279 Share on other sites More sharing options...
coupe-r Posted December 16, 2011 Share Posted December 16, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/253222-newbie-problem-with-echo/#findComment-1298417 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.