Hi,

I'm trying to use this code (found it on codewalkers). It was working fine, I have changed login variable to be login instead of Login. It gave me undefined PHP_SELF so I replaced the following line:

<form id="form1" name="form1" method="post" action="<? echo $PHP_SELF;>"> 

with this:

<form id="form1" name="form1" method="post" action="<? echo $_SERVER['PHP_SELF']?>"> 

Now its giving me error on line 13 which is this line:

$Login = $_POST['login'];

I don't know why? I mean for me I cant see where the error in that line is.

Any help,

Thanks so much

Here is almost the whole code that I'm using:

<?
//Use session variable on this page. This function must put on the top of page.
session_start();

//Logout Section. Delete all session variable.
session_destroy();

include_once("include/db_connection.php");

$message="";

//Login Section
$Login=$_POST['login'];

if($Login){ // if clicked on Login button.
   $username=$_POST['username'];
   $md5_password=md5($_POST['password']); // Encrypt password with md5() function. 

   //Check matching of username and password.
   $result=mysql_query("select * from reviewer where username='$username' and password='$md5_password'");
   if(mysql_num_rows($result)!='0'){ // if match.
      session_register("username"); // Craete session username.
      header("location:main.php"); // Re-direct to main.php
      exit;
}else { // if not match.
    $message="<font size='3' color='red'>--- Incorrect username or password. Please try again ---</font>";
}

} // End Login authorize check.
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome to Movies Reviews</title>
</head>

<body>
<?php echo $message; ?>
<form id="form1" name="form1" method="post" action="<? echo $_SERVER['PHP_SELF']?>"> 
  <table>
    <tr>
      <td>User : </td>
.....

    Undefined index is proably because you have forgotten to name correctly / include the input object that is supposed to be found as a variable in the $_POST['login'] line. Check the contents of your form to make sure you have the Login button named 'login'.

    e.g. <input type="submit" value="log me in button" name="login"> should be in your form somewhere.

    hth

      Its there, sorry I didn't post it in my previous post:

      <input name="Login" type="submit" id="login" value="login" />

      its same as the variable (login) but still not working.

        Either change

        <input name="Login" type="submit" id="login" value="login" />

        to

        <input name="Login" type="submit" id="Login" value="login" />

        or eliminate the id name atttribute is usually what is looked for but with XHTML the id attribute was added so they must both be the same if you use the id attribute and your code has them both ways no wonder PHP can't figure it out.

          Thanks a lot, thats solved it.

            Write a Reply...