Cory94bailly Posted May 13, 2008 Share Posted May 13, 2008 <?php // Connects to your Database mysql_connect("***", "***", "***") or die(mysql_error()); mysql_select_db("***") or die(mysql_error()); //**********Start Member Login!**********\\ if(isset($_POST['login'])) { //Checks if there is a login cookie if(isset($_COOKIE['ID_fcs'])) //if there is, it logs you in and directes you to the members page { $username = $_COOKIE['ID_fcs']; $pass = $_COOKIE['Key_fcs']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: members.php"); } } } //if the login form is submitted if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['username'] | !$_POST['pass']) { die('You did not fill in a required field.'); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href=register.php>Click Here to Register</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); $_POST['pass'] = md5($_POST['pass']); //gives error if the password is wrong if ($_POST['pass'] != $info['password']) { die('Incorrect password, please try again.'); } else { // if login is ok then we add a cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_fcs, $_POST['username'], $hour); setcookie(Key_fcs, $_POST['pass'], $hour); //then redirect them to the members area header("Location: members.php"); } } } } else { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!-- Author: Reality Software Website: http://www.realitysoftware.ca Note: This is a free template released under the Creative Commons Attribution 3.0 license, which means you can use it in any way you want provided you keep the link to the author intact. --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Free Configuration Service Official Website</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> < <body> <!-- header --> <div id="header"> <div id="menu"> <div id="menu_list"> <a href="index.php">Home</a> <img src="images/splitter.gif" class="splitter" alt="" /> <a href="aboutus.php">About Us</a> <img src="images/splitter.gif" class="splitter" alt="" /> <a href="services.php">Services</a> <img src="images/splitter.gif" class="splitter" alt="" /> <a href="team.php">Team</a> <img src="images/splitter.gif" class="splitter" alt="" /> <a href="login.php"><font color=red>Login</font></a> </div> </div> </div> <? include('includes/logo.php'); ?> </div> <!--end header --> <!-- main --> <div id="main"> <? include('includes/right.php'); ?> </div> <p><center><strong><font size="25">Not Finished!</font></strong></center></p> <div id="text" > <h1>Member Login</h1> <p><form action="<? $_SERVER['PHP_SELF'] ?>" method="post"> <table border="0"> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="login" value="Login"> </td></tr> </table> </form> <p>Don't have an account? <a href="register.php">Click Here!</a></p></p> <h1>Team Login</h1> <p><form action="<? $_SERVER['PHP_SELF'] ?>" method="post"> <table border="0"> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="teamlogin" value="Login"> </td></tr> </table> </form></p> </div> <!-- end main --> <? include('includes/footer.php'); ?> </body> </html> <? } ?> That's the whole script.. What's wrong with it? When I click submit for the member's login, I just get a blank page. (I know the team login doesn't work yet.. I didn't put it in ) Link to comment https://forums.phpfreaks.com/topic/105511-solved-how-is-this-code-wrong/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 13, 2008 Share Posted May 13, 2008 Blank php pages are almost always caused by fatal parse errors. In your case - Parse error: syntax error, unexpected $end in ...\yourfile.php on line 154 This is caused by the use of short open tags <?. Be consistent and always use full <?php tags. And if fixing the <? tags does not result in any output, then set error_reporting to E_ALL and display_errors on in your php.ini or a .htaccess file to get php to help you. Link to comment https://forums.phpfreaks.com/topic/105511-solved-how-is-this-code-wrong/#findComment-540456 Share on other sites More sharing options...
Cory94bailly Posted May 13, 2008 Author Share Posted May 13, 2008 But I am not getting Parse error: syntax error, unexpected $end in ...\yourfile.php on line 154 anymore.. I am now just getting a totally blank page. Link to comment https://forums.phpfreaks.com/topic/105511-solved-how-is-this-code-wrong/#findComment-540460 Share on other sites More sharing options...
haku Posted May 14, 2008 Share Posted May 14, 2008 Did you even try the suggestion given? The answer as to why you aren't getting errors is in it. If you are asking for help, you should at least attempt to try to follow the advice given. Link to comment https://forums.phpfreaks.com/topic/105511-solved-how-is-this-code-wrong/#findComment-540582 Share on other sites More sharing options...
revraz Posted May 14, 2008 Share Posted May 14, 2008 Say what? That error is not caused by short tags, sorry. You probably have a missing closing } ) somewhere. But it is possible the short tag here is stopping the } from being read at the end of the code. <? } ?> Blank php pages are almost always caused by fatal parse errors. In your case - Parse error: syntax error, unexpected $end in ...\yourfile.php on line 154 This is caused by the use of short open tags <?. Be consistent and always use full <?php tags. And if fixing the <? tags does not result in any output, then set error_reporting to E_ALL and display_errors on in your php.ini or a .htaccess file to get php to help you. Link to comment https://forums.phpfreaks.com/topic/105511-solved-how-is-this-code-wrong/#findComment-540589 Share on other sites More sharing options...
haku Posted May 14, 2008 Share Posted May 14, 2008 Which, if that is the case, would mean that while the error may not be caused by the short tags, its a direct result of their usage. Link to comment https://forums.phpfreaks.com/topic/105511-solved-how-is-this-code-wrong/#findComment-540601 Share on other sites More sharing options...
PFMaBiSmAd Posted May 14, 2008 Share Posted May 14, 2008 And if you read carefully, I did not state the error was cause by short open tags it is caused by the use of short open tags. Link to comment https://forums.phpfreaks.com/topic/105511-solved-how-is-this-code-wrong/#findComment-540612 Share on other sites More sharing options...
PFMaBiSmAd Posted May 14, 2008 Share Posted May 14, 2008 Cory94bailly, I went back and looked at the code you posted. It is not formatted/indented so no one is really able to easily see what it is logically doing. However, if you do go through it and format and indent it, you will find that inside of your main if() statement, you are testing - if (isset($_POST['submit'])) { // if form has been submitted This variable does not exist in the form(s) and will never be set. This causes all of the remainder of the code in the main if() to be skipped, resulting in no output. Debugging code involves playing computer and stepping through each line and determining if the code does what you expect and that each possible conditional branch does what you expect. It also involves checking if variables exist and that they contain expected values. You also are missing echo statements before each $_SERVER['PHP_SELF'] in the form action="..." parameters. Link to comment https://forums.phpfreaks.com/topic/105511-solved-how-is-this-code-wrong/#findComment-540653 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.