Jump to content

Login Script


INeedAGig

Recommended Posts

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! :)

 

 

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.