clanstyles Posted July 18, 2007 Share Posted July 18, 2007 My login script is just not working in general. It has to do with $errorMessage1 and printing out. The other stuff works fine like actually loging the user in ect.. Itsjust sometimes it returns BLAnk stuff and other times its not and has the same error repeating ect.. Thanks <?php if(isset($_POST['login'])) { $errorMessage1 = "1"; $username = cleanstr($_POST['username']); $password = md5(cleanstr($_POST['pass'])); if(empty($username) || empty($password)) $errorMessage1 .= "Please fill in a username and password.<br /><br />"; if($_SESSION['capkey'] != md5($_POST['img'])) $errorMessage1 .= "Wrong image verification.<br />"; if($errorMessage1 != "1") $errorMessage1 = str_replace("1", "", $errorMessage1); echo $errorMessage1; if($errorMessage1 == null) { $result = mysql_query("SELECT * FROM `accounts` WHERE `username`='$username' AND `password`='$password' LIMIT 1") or die(mysql_error()); while($res = mysql_fetch_array($result)) { if(mysql_num_rows($result) == 1) { if($res['verified'] != "1") { echo "Please verifiy this account before proceeding.<br />"; } else { session_register("id"); session_register("username"); session_register("hasLogin"); $_SESSION['hasLogin'] = true; $_SESSION['id'] = $res['id']; $_SESSION['username'] = $username; } } else { $errorMessage1 .= "Login incorrect"; echo "Login incorrect.<br />"; } } } else { echo "You logged in wrong. Click <a href=\"?\">here</a> to try again."; } } if($errorMessage1 != "1") echo "<font color=\"red\">".$errorMessage1."</font>"; if(!isLogedin() && empty($errorMessage1)) { ?> <form id="login" name="login" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data"> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td>User: </td> <td><input type="text" name="username" id="username" class="text" align="right" /></td> </tr> <tr> <td>Pass: </td> <td><input type="password" name="pass" id="pass" class="text" align="right" /></td> </tr> <tr> <td>Verify</td> <td><input type="text" name="img" id="img" class="text" align="right" /></td> </tr> <tr> <td></td> <td><img src="captcha.php" alt=""></td> </tr> <tr> <td></td> <td><input type="submit" name="login" id="login" value="Submit" class="searchbutton" /></td> </tr> </table> </form> <?php } else if($errorMessage1 != "1" && !isLogedin()) { echo "Incorrect login. Click <a href=\"?\">here</a> to try again."; } else if(isset($errorMessage)) echo "<font color=\"red\">".$errorMessage1."</font>"; if(isLogedin()) { ?> <a href="?page=accountarea&place=usercp">User CP<a/><br /> <a href="#">Subscription Plan<a/><br /> <a href="#">Upgrade Subscription<a/><br /> <a href="#">Private Messaging<a/><br /> <a href="#">Forums<a/><br /> <?php if(checkRank(1)) { echo "<a href=\"?page=accountarea&place=adminarea\">Admin Area</a><br />"; } } ?> Quote Link to comment Share on other sites More sharing options...
clanstyles Posted July 18, 2007 Author Share Posted July 18, 2007 Updated some code...Fixed most of the bugs but ONE.. <?php if(isset($_POST['login'])) { $theErrorMessage = ""; $username = cleanstr($_POST['username']); $password = md5(cleanstr($_POST['pass'])); if(empty($username) || empty($password)) $theErrorMessage .= "Please fill in a username and password.<br /><br />"; if($_SESSION['capkey'] != md5($_POST['img'])) $theErrorMessage .= "Wrong image verification.<br />"; if(empty($theErrorMessage)) { $result = mysql_query("SELECT * FROM `accounts` WHERE `username`='$username' AND `password`='$password' LIMIT 1") or die(mysql_error()); while($res = mysql_fetch_array($result)) { if(mysql_num_rows($result) == 1) { $isNotCorrect = false; if($res['verified'] != "1") { echo "Please verifiy this account before proceeding.<br />"; } else { session_register("id"); session_register("username"); session_register("hasLogin"); $_SESSION['hasLogin'] = true; $_SESSION['id'] = $res['id']; $_SESSION['username'] = $username; } } else { $theErrorMessage .= "Wrong login information. Click <a href=\"?\">here</a> to try again."; } } } else { $theErrorMessage .= "Wrong login information. Click <a href=\"?\">here</a> to try again."; } } if(!empty($theErrorMessage)) echo $theErrorMessage; if(!isLogedin() && empty($theErrorMessage)) { ?> <form id="login" name="login" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data"> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td>User: </td> <td><input type="text" name="username" id="username" class="text" align="right" /></td> </tr> <tr> <td>Pass: </td> <td><input type="password" name="pass" id="pass" class="text" align="right" /></td> </tr> <tr> <td>Verify</td> <td><input type="text" name="img" id="img" class="text" align="right" /></td> </tr> <tr> <td></td> <td><img src="captcha.php" alt=""></td> </tr> <tr> <td></td> <td><input type="submit" name="login" id="login" value="Submit" class="searchbutton" /></td> </tr> </table> </form> <?php } if(isLogedin()) { ?> <a href="?page=accountarea&place=usercp">User CP<a/><br /> <a href="#">Subscription Plan<a/><br /> <a href="#">Upgrade Subscription<a/><br /> <a href="#">Private Messaging<a/><br /> <a href="#">Forums<a/><br /> <?php if(checkRank(1)) { echo "<a href=\"?page=accountarea&place=adminarea\">Admin Area</a><br />"; } } ?> problem occurs here else { $theErrorMessage .= "Wrong login information. Click <a href=\"?\">here</a> to try again."; } It isan't hitting this and saying wrong login. It just redraws the form since there is no error in $theErrorMessage. I tried echoing just for fun in there to see if it is ever run and nope. Quote Link to comment Share on other sites More sharing options...
lewis987 Posted July 18, 2007 Share Posted July 18, 2007 <?PHP else { $theErrorMessage .= "Wrong login information. Click <a href=\"?\">here</a> to try again."; } ?> Changes to: else { $theErrorMessage = "Wrong login information. Click <a href=\"?\">here</a> to try again."; } and at the start it should be (or anywhere before the login check): $theErrorMessage = ""; and on the form you should have: <?PHP echo $theErrorMessage; ?> so it shows the user that the wrong information is entered. Quote Link to comment Share on other sites More sharing options...
clanstyles Posted July 18, 2007 Author Share Posted July 18, 2007 na not that and i do have that if(!empty($theErrorMessage)) echo $theErrorMessage; is right before the form starts. Quote Link to comment Share on other sites More sharing options...
clanstyles Posted July 19, 2007 Author Share Posted July 19, 2007 bump 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.