Pain Posted April 2, 2010 Share Posted April 2, 2010 Hello everyone. I am learning how to use PHP and i would like to get some help. For example i wrote this crappy code: <html> <head> <title> Login </title> <body> <?php $username = "username"; $password = "password"; $wel = "You have successfully logged in $username"; $get = "Incorrect username or password"; $vardas = $_POST['vardas']; $slaptazodis = $_POST['slaptazodis']; <form method="POST" action="'. $_SERVER['PHP_SELF'] . '"> <input type="text" name="vardas"> <input type="text" name="slaptazodis"> <input type="submit" /> </form> if ($username != $vardas) { print $get; { elseif ($password != $slaptazodis) print $get; } } else { print $wel; } ?> </body> </html> Can't figure out what is wrong with it. I get this: Parse error: syntax error, unexpected '<' in /home/a2789128/public_html/a/Login.php on line 14 Thank you for your help:) Quote Link to comment https://forums.phpfreaks.com/topic/197412-need-a-little-help/ Share on other sites More sharing options...
oni-kun Posted April 2, 2010 Share Posted April 2, 2010 PHP is not HTML, so it can't be used in the same tags. You need to separate them, Let me show you an example of your working code: <html> <head> <title> Login </title> <body> <?php $username = "username"; $password = "password"; $wel = "You have successfully logged in $username"; $get = "Incorrect username or password"; $vardas = $_POST['vardas']; $slaptazodis = $_POST['slaptazodis']; ?> <form method="POST" action="<?php print $_SERVER['SCRIPT_NAME']; ?>"> <input type="text" name="vardas"> <input type="text" name="slaptazodis"> <input type="submit" /> </form> <?php if ($username != $vardas) { print $get; } elseif ($password != $slaptazodis) { print $get; } else { print $wel; } ?> </body> </html> Although it still looks like there are many problems with your structures, You should learn how to use IF statements properly, as I needed to correct quite a few. Try not to list the curly braces ({ }) on new lines, as it seems you're confusing them in the end. For security reasons, also use SCRIPT_NAME in place of PHP_SELF, which will work the same in the end. This code will not work, as you need to look into ISSET for your $_POST elements as well. If you need help on that just ask. Quote Link to comment https://forums.phpfreaks.com/topic/197412-need-a-little-help/#findComment-1036192 Share on other sites More sharing options...
Pain Posted April 2, 2010 Author Share Posted April 2, 2010 Thank you for your help. Everyone's a noob in the beginning. >.< Quote Link to comment https://forums.phpfreaks.com/topic/197412-need-a-little-help/#findComment-1036202 Share on other sites More sharing options...
Pain Posted April 3, 2010 Author Share Posted April 3, 2010 Ok i modified it a bit, but it still doesnt look good. Anny suggestions how to improve it:(? <html> <head> <title> Login </title> <body> <?php $user = "asesu1"; $pass = "asesu2"; $username = $_POST['username']; $password = $_POST['password']; if ($username != $user) { if ($password != $pass) { print' <form method="POST" action="'. $_SERVER['PHP_SELF'] . '"> Login:<br/> <input type="text" name="username" size="14"><br/> Password:<br/> <input type="password" name="password" size="14"><br/> <input type="submit" value="Jungti" name="B1"> <input type="reset" value="Valyti" name="B2"> </form>'; } } else { ?> <p align="center"> <br/> <br/> <br/> <br/> <b>Welcome!</b> <br/> <br/> Vla bla bla</p> <? } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/197412-need-a-little-help/#findComment-1036213 Share on other sites More sharing options...
crawlerbasher Posted April 3, 2010 Share Posted April 3, 2010 When I was learning the basics of PHP I found this book very useful. Sams teach your self php, mysql database and appachy in 24 hours. It showed me some every day use of php and gived me a better understanding. The book will not teach everything, just the basics to help you understand and learn basic scripting. And as you start to get better you can start to desgin your own guest book and interactive pages. This site and a forum is a great place for information and help if you get stuck. And www.php.net has loads of information on diffrent codes and funcanlitys. Quote Link to comment https://forums.phpfreaks.com/topic/197412-need-a-little-help/#findComment-1036222 Share on other sites More sharing options...
mikesta707 Posted April 3, 2010 Share Posted April 3, 2010 this if ($username != $user) { if ($password != $pass) { print' <form method="POST" action="'. $_SERVER['PHP_SELF'] . '"> Login:<br/> <input type="text" name="username" size="14"><br/> Password:<br/> <input type="password" name="password" size="14"><br/> <input type="submit" value="Jungti" name="B1"> <input type="reset" value="Valyti" name="B2"> </form>'; } } can be simplified to if ($password != $pass && $username != $user) { print' <form method="POST" action="'. $_SERVER['PHP_SELF'] . '"> Login:<br/> <input type="text" name="username" size="14"><br/> Password:<br/> <input type="password" name="password" size="14"><br/> <input type="submit" value="Jungti" name="B1"> <input type="reset" value="Valyti" name="B2"> </form>'; } Quote Link to comment https://forums.phpfreaks.com/topic/197412-need-a-little-help/#findComment-1036233 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.