-1

Ive got some problems when trying to log in to my page. always get wrong username and password error with Notice: Undefined index..... line 30-32 here is my code:

<?php 
include("start.html");
include("db-connect.php");
include("sjekk.php");
?>

<form method="post" action="" id="loggInn" name="loggInn">
<fieldset class="container">
<legend>Logg inn</legend>
<table>
    <tr>
    <td><label>Brukernavn </td><td> <input type="text" id="brukernavn" name="brukernavn"> <br/></label></td>
    </tr>
    <tr>
    <td><label>Passord </td><td>  <input type="password" id="passord" name="passord"> <br/></label></td>
    </tr>
    <tr>
    <td><input type="submit" value="Logg inn" id="loggInnKnapp" name="loggInnKnapp" /> </td>
    <td><input type="reset" value="Nullstill" id="nullstill" name="nullstill" /> <br /></td>
    </tr>
    </table>
</fieldset>
</form>
<br />


<?php 


$brukernavn=$_POST ["brukernavn"];
$passord=$_POST["passord"]; 
$login=$_POST[loggInnKnapp];

if($login)
{
if (!sjekkBrukernavnOgPassord($brukernavn,$passord)) 
    {

mysql_query($sqlSentence) or die ("<p>Feil brukernavn/passord.</p>".file_get_contents("slutt.html"));

    }
else        
    {
        print("<p>Du er n&aring logget inn.</p>");
    }               
}


if (!sjekkBrukernavnOgPassord($brukernavn,$passord))  
{
    print("Feil brukernavn/passord <br />");
}
else  
{
    @session_start();
    $_SESSION["innlogget"]=1;  

    print("I menyen til venstre finner du ulike valg som kan utføres ved bruk av denne applikasjonen");
}   
?>
<p>Ny bruker?</p>
<a href="reg-bruker.php">Registrer deg her</a>
<?php
include("slutt.html");
?>

dont know why I get these errors, been looking over the codes for a couple of days and cant figuere it out

  • Make sure you have quotes on $_POST[loggInnKnapp]; to make $_POST["loggInnKnapp"]; – H2ONOCK Apr 18 '13 at 10:31
  • Giving a useful part of the error message could be helpful. For instance, `Undefined index [add the next string here]` and you can skip the filepath – Emmanuel Okeke Apr 18 '13 at 10:38

2 Answers2

0

You get the error, because an index of the $_POST array doesn't exists. First $_POST[loggInnKnapp] should be $_POST['loggInnKnapp'] and you should test if the variable exists before you assign the value to the new variables:

if(isset($_POST["brukernavn"]) && isset($_POST["passord"]) && isset($_POST['loggInnKnapp'])) {
   $brukernavn=$_POST ["brukernavn"];
   $passord=$_POST["passord"]; 
   $login=$_POST["loggInnKnapp"];
   //The rest of your code
}
Sébastien Garmier
  • 1,263
  • 9
  • 16
-1

Your reference should be in single quotes:

$login=$_POST[loggInnKnapp];

should be:

$login=$_POST['loggInnKnapp'];
Borniet
  • 3,544
  • 4
  • 24
  • 33