kir Posted April 23, 2014 Share Posted April 23, 2014 I am getting tons of errors when I try and run this.... If you can find out why plz post it below! Thanks in advance. -------------------------------------------------------------------------- <?php error_reporting (E_ALL ^ E_NOTICE); session_start(); ?> <!DOCTYPE html PUBLIC> <html> <head> <title>Login</title> </head> <body> <?php $form = "<form action='./login.php' method='post'>" <table> <tr> <td>Username:</td> <td><imput type='text' name='user' /></td> </tr> <tr> <td>Password:</td> <td><imput type='password' name='password' /></td> </tr> <tr> <td></td> <td><imput type='submit' name='loginbtn' value='Login' /></td> </tr> </tr> </table> </form>"; if ($_POST['loginbtn']){ $user = $_POST['user']; $password = $_POST['password']; if ($user){ if ($password){ echo "$user - $password <hr /> $form"; } else echo "You must enter your password. $form"; } else echo "You must enter your username. $form"; } else echo $form; ?> </body> </html> --------------------------------------------------------------------------------- Quote Link to comment https://forums.phpfreaks.com/topic/287982-syntax-errors/ Share on other sites More sharing options...
ginerjm Posted April 23, 2014 Share Posted April 23, 2014 1 - read the rules and post using the proper tags. 2 - how about giving us a couple of your error messages? 3 - php statements must end with a semi 4 - separate your html code from your php code and you won't leave php mode on while you are typing html and vice versa. Coders who mingle html/js/php in their scripts are just asking for pain and confusion. Quote Link to comment https://forums.phpfreaks.com/topic/287982-syntax-errors/#findComment-1477137 Share on other sites More sharing options...
Cornelius Posted April 24, 2014 Share Posted April 24, 2014 (edited) - your file should also be named login.php - line 16 - you can't make php variable equal to HTML tags - you have multiple syntax error 'imput' instead of 'input' <?php error_reporting (E_ALL ^ E_NOTICE); session_start(); ?> <!DOCTYPE html PUBLIC> <html> <head> <title>Login</title> </head> <body> <form action='./login.php' method='post'> <table> <tr> <td>Username:</td> <td><input type='text' name='user' /></td> </tr> <tr> <td>Password:</td> <td><input type='password' name='password' /></td> </tr> <tr> <td></td> <td><input type='submit' name='loginbtn' value='Login' /></td> </tr> </tr> </table> </form> <!-- PHP form handling code starts here --> <?php if ($_POST['loginbtn']){ $user = $_POST['user']; $password = $_POST['password']; if ($user){ if ($password){ echo "$user - $password <hr /> $form"; } else echo "You must enter your password. $form"; } else echo "You must enter your username. $form"; } else echo $form; ?> </body> </html> Edited April 24, 2014 by Cornelius Quote Link to comment https://forums.phpfreaks.com/topic/287982-syntax-errors/#findComment-1477147 Share on other sites More sharing options...
Ch0cu3r Posted April 24, 2014 Share Posted April 24, 2014 - line 16 - you can't make php variable equal to HTML tags Aslong as the HTML is enclosed in quotes that is fine. The problem with the OP's code is the double quote at the end of line 16 Quote Link to comment https://forums.phpfreaks.com/topic/287982-syntax-errors/#findComment-1477156 Share on other sites More sharing options...
Cornelius Posted April 24, 2014 Share Posted April 24, 2014 (edited) Oh, I agree. Generally you can make a string variable containing some HTML (or whichever) code. $name = "John"; $op_tags = "<b>"; $end_tags="</b>"; echo "You must enter your password, $op_tags $name $end_tags."; which would output: You must enter your password, John . My impression was that OP was hoping to put the whole HTML form inside a variable for execution purpose (if it can be said like that). In my example in previous post, he should also delete all $form because they have no purpose anymore. Edited April 24, 2014 by Cornelius Quote Link to comment https://forums.phpfreaks.com/topic/287982-syntax-errors/#findComment-1477161 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.