Hello, I am trying to modify a login php script found at: http://www.evolt.org/node/60265 Basically, I just want to enter one username and password by hand, not via MySQL. Meaning that if the two right terms are entered (both are drewtoby), you are logged in. If any other terms are entered, you are not. The issue appears to be wrong syntax (as I am new to php ). The error is: Parse error: syntax error, unexpected T_VARIABLE in W:\web\wallpaper4cash\login\register.php on line 33 Code (markup): The code is: <? session_start(); include("database.php"); if(0==1){ } if (1==1) { /** * This is the page with the sign-up form, the names * of the input fields are important and should not * be changed. */ ?> <html> <title>Login Page</title> <body> <h1>Login</h1> <form action="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr> <tr><td colspan="2" align="right"><input type="submit" name="subjoin" value="Login!"></td></tr> </table> </form> </body> </html> <? } if (($user=drewtoby)$pass=drewtoby) // this is the bad line. { ?> <html> <h1>Login</h1> </html> <? } Code (markup): Any help would be greatly appreciated. Thanks!
try to erase it first, it seems that you want to initialize a variable, erase it first see if it works. put the initialization outside the if condition
Here is your code that works: <?php session_start(); include("database.php"); if(0==1) { } if (1==1) { /** * This is the page with the sign-up form, the names * of the input fields are important and should not * be changed. */ ?> <html> <head> <title>Login Page</title> </head> <body> <h1>Login</h1> <form action="<?php echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr> <tr><td colspan="2" align="right"><input type="submit" name="subjoin" value="Login!"></td></tr> </table> </form> </body> </html> <?php } if (($user=drewtoby)$pass=drewtoby) // this is the bad line. { ?> <html> <body> <h1>Login</h1> </body> </html> <?php } ?> PHP: Use <?php ?> instead of <? ?> (that is not why parse error happened but it's good to be precise. You didn't close if statement.
Actual problem not yet addressed. Please see the highlighted line which causes the problem. <? session_start(); include("database.php"); if(0==1){ } if (1==1) { /** * This is the page with the sign-up form, the names * of the input fields are important and should not * be changed. */ ?> <html> <title>Login Page</title> <body> <h1>Login</h1> <form action="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr> <tr><td colspan="2" align="right"><input type="submit" name="subjoin" value="Login!"></td></tr> </table> </form> </body> </html> <? } [COLOR="red"]if (($user=drewtoby)$pass=drewtoby) // this is the bad line. [/COLOR] { ?> <html> <h1>Login</h1> </html> <? } ?> Code (markup): The highlighted line is really bad , drewtoby is a string which is not quoted. So the revised code will be as follows: <? session_start(); include("database.php"); if(0==1){ } if (1==1) { /** * This is the page with the sign-up form, the names * of the input fields are important and should not * be changed. */ ?> <html> <title>Login Page</title> <body> <h1>Login</h1> <form action="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr> <tr><td colspan="2" align="right"><input type="submit" name="subjoin" value="Login!"></td></tr> </table> </form> </body> </html> <? } [COLOR="red"]if (($user="drewtoby") $pass="drewtoby") // this is the good line now. [/COLOR] { ?> <html> <h1>Login</h1> </html> <? } ?> Code (markup):
Okay, I re-wrote the lines and have a new issue >.< The code to be displayed AFTER login is now being shown NEXT to the login script =( the code is: <? session_start(); ?> <html> <title>Login Page</title> <body> <h1>Login</h1> <form action="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr> <tr><td colspan="2" align="right"><input type="submit" name="subjoin" value="Login!"></td></tr> </table> </form> </body> </html> <? if (($user="drewtoby") && ($pass="drewtoby")) { ?> <html> <b>Login</b> </html> <? } ?> Code (markup):
Learn PHP thoroughly before starting development. Get reference from W3Schools, PHP.NET, Tizaq etc. Because the question you've asked is even simpler than basic. You've to add the HTML form in else part of the if() block which checks username. IMO: A Forum is not a good place to getting started with any language. Do submit your doubts and troubles. But, you can't learn PHP properly if you aim to learn the entire language by asking questions on this forum. I hope, you won't take this advice negatively...
Yes, at techbongo said, i want you to have a look on the tutorial sites such w3schools, tizag where you can get basic idea of all. If you want some free sample scripts then i suggest you to visit plus2net.com/php_tutorial/site_map.php. Thanks.