Cyan Posted July 13, 2014 Share Posted July 13, 2014 Just new to this website and I keep getting several errors in my "else" code. I can't seem to find wrong codes in it (I'm just a rookie in programming) My codes is here: <?php $username = $_POST['username']; $password = $_POST['password']; if ($username == '12345' and $password == '12345'); { echo '<h1> Welcome To The Site! </h1> <br> <br> <br> This site will let you post your ideas! <br>'; } else { echo 'Wrong Username and Password'; } ?> I keep having errors in bold text. Since I'm new at programming, I don't understand some errors that were shown to me in the actual site. The only error that I get is (T_ELSE) which I don't understand. So can someone help me what should I do with it since I'm just new. (I am also new to the site so I'm sorry if I did anything wrong) Quote Link to comment Share on other sites More sharing options...
ajhanna88 Posted July 13, 2014 Share Posted July 13, 2014 remove the semicolon from the end of this line if ($username == '12345' and $password == '12345'); Quote Link to comment Share on other sites More sharing options...
Cyan Posted July 13, 2014 Author Share Posted July 13, 2014 Hmm... that removed the (T_ELSE) error but I still got an error which is "Unidentified index: Username/Password" Quote Link to comment Share on other sites More sharing options...
Cyan Posted July 13, 2014 Author Share Posted July 13, 2014 Still can't figure out how to fix it... can someone help me? Quote Link to comment Share on other sites More sharing options...
ajhanna88 Posted July 13, 2014 Share Posted July 13, 2014 (edited) I have tested your code and it works fine for me, I would check to make sure that username and password variables are getting set e.g. if(isset($_POST['username'])){ $username = $_POST['username']; } Edited July 13, 2014 by ajhanna88 Quote Link to comment Share on other sites More sharing options...
Barand Posted July 13, 2014 Share Posted July 13, 2014 It sounds like you are running the script without sending any POST data to it. You need check if the data exists. $username = isset($_POST['username'] ? $_POST['username'] : ''; $password = isset($_POST['password'] ? $_POST['password'] : ''; Quote Link to comment Share on other sites More sharing options...
adam_bray Posted July 13, 2014 Share Posted July 13, 2014 You should also tidy up your HTML, using line breaks like you have is pointless. '<h1> Welcome To The Site! </h1> <p>This site will let you post your ideas!</p>'; Use CSS to specify margins and padding between elements, not line breaks. Quote Link to comment 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.