INeedAGig Posted March 29, 2011 Share Posted March 29, 2011 Okay, a few of you have been helping me with a login script problem. I have changed it quite a bit again, but I am still running into a little bit of a problem. When I click the submit button it just clears the form fields and stays on the login page. Also, I have used error_reporting(E_ALL) to help me out with debugging. I took care of three bugs on my own but I cant seem to clear the two remaining bugs and the fact that it is not forwarding me to any page with my header statement. Thanks for your help in advance! Here is my code from my 'login.php' file. <?php session_start(); error_reporting (E_ALL); include("config.php"); if($_SERVER["REQUEST_METHOD"] == "POST") { // username and password sent from form $myusername=addslashes($_POST['username']); $mypassword=addslashes($_POST['password']); $sql="SELECT id FROM admin WHERE username='$myusername' and passcode='$mypassword'"; $result=mysql_query($sql); $row=mysql_fetch_array($result); $active=$row['active']; $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1) { session_register("myusername"); $_SESSION['login_user']=$myusername; header("location: main_interface.php"); } else { $error="The username or password you entered is invalid, please check your credentials and try again"; } } ?> <form action="" method="post"> <label>Username :</label> <input type="text" name="username"/><br /> <label>Password :</label> <input type="password" name="password"/><br/> <input type="submit" value=" Submit "/><br /> </form> Here are the error messages on the page Notice: Undefined index: active in login.php on line 20 Warning: Cannot modify header information - headers already sent by (output started at login.php:1) in login.php on line 29 Thanks in advance for your help! Quote Link to comment https://forums.phpfreaks.com/topic/232017-login-script/ Share on other sites More sharing options...
trq Posted March 29, 2011 Share Posted March 29, 2011 The undefined index error occurs because your query only selects the id from the database yet your trying to access a filed called 'active'. This error in turn generates output which causes your header error. ps: session_register() has long been deprecated and should no longer be used. Quote Link to comment https://forums.phpfreaks.com/topic/232017-login-script/#findComment-1193560 Share on other sites More sharing options...
INeedAGig Posted March 29, 2011 Author Share Posted March 29, 2011 What should I use in place of session_register()? Quote Link to comment https://forums.phpfreaks.com/topic/232017-login-script/#findComment-1193561 Share on other sites More sharing options...
INeedAGig Posted March 29, 2011 Author Share Posted March 29, 2011 Alright, I have it down to just the: Warning: Cannot modify header information - headers already sent by (output started at login.php:1) in login.php on line 26 Quote Link to comment https://forums.phpfreaks.com/topic/232017-login-script/#findComment-1193562 Share on other sites More sharing options...
trq Posted March 29, 2011 Share Posted March 29, 2011 What should I use in place of session_register()? Nothing, you simply don't need that line. There is a sticky at the top of this board that covers this header error. it's probably the most common error newcomer come across. Quote Link to comment https://forums.phpfreaks.com/topic/232017-login-script/#findComment-1193563 Share on other sites More sharing options...
INeedAGig Posted March 29, 2011 Author Share Posted March 29, 2011 Yeah, I deleted that line and it took care of it. I will check out the sticky, I forgot all about it actually. Quote Link to comment https://forums.phpfreaks.com/topic/232017-login-script/#findComment-1193564 Share on other sites More sharing options...
PFMaBiSmAd Posted March 29, 2011 Share Posted March 29, 2011 LOL, you are back at the point of needing to read and follow the first two replies in the last thread you started for this code - Your header() redirect is probably failing due to your script outputting some blank lines at the start of your file before the <?php tag. Are you developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON so that all the php detected errors will be reported and displayed? You will save a TON of time. Also, session_register() was depreciated almost 9 years ago and won't work on a majority of php installations today and is going to be removed in the next major php version release. You should be setting and referencing $_SESSION variables and you will need a session_start() statement in your code before you output anything to the browser. You need to put the error_reporting() statement after the line with the first <?php tag and before any other code so that you will see ALL the errors. Quote Link to comment https://forums.phpfreaks.com/topic/232017-login-script/#findComment-1193619 Share on other sites More sharing options...
INeedAGig Posted March 29, 2011 Author Share Posted March 29, 2011 LOL, you are back at the point of needing to read and follow the first two replies in the last thread you started for this code - Your header() redirect is probably failing due to your script outputting some blank lines at the start of your file before the <?php tag. Are you developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON so that all the php detected errors will be reported and displayed? You will save a TON of time. Also, session_register() was depreciated almost 9 years ago and won't work on a majority of php installations today and is going to be removed in the next major php version release. You should be setting and referencing $_SESSION variables and you will need a session_start() statement in your code before you output anything to the browser. You need to put the error_reporting() statement after the line with the first <?php tag and before any other code so that you will see ALL the errors. I've done all that Hehe, and it was my mistake with the session_register() this time, I just modified a previous file I had saved and forgot to remove it....again...lol. But, I reviewed everything from my last post and am only down to that one error. I have verified that there is nothing being processed before the initial <?php tag Quote Link to comment https://forums.phpfreaks.com/topic/232017-login-script/#findComment-1193741 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.