I have a login form and i want to enter username & password to log into the system.
When loading the page (index.php) there was an error displayed like this.

Notice: Undefined index: msg in C:\wamp\www\Home page\new student registration\index.php on line 13

index.php

<form id="form1" name="form1" method="post" action="adminloginvalidate.php">
<?php
$message=$_POST["msg"]; [B][line 13][/B]
?>
<table width="499" align="center">

  <tr>
    <td width="520" height="125" valign="top">&nbsp;</td>
  </tr>
  <tr>
    <td height="284" valign="top" background="images/logo_image.png"><table width="468" border="0">
      <tr>
        <td width="28">&nbsp;</td>
        <td width="58">&nbsp;</td>
        <td colspan="2">&nbsp;</td>
        <td width="150">&nbsp;</td>
        <td width="89">&nbsp;</td>
        <td width="14">&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td colspan="2">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="5" align="center"><label><strong>STUDENT MANAGEMENT SYSTEM</strong></label>          &nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="5" align="center">Subarathi Vidyalaya Godagama</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td colspan="2">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="5" align="center"><label>Please enter your user name and password</label>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td colspan="2"><label>User Name</label>
          &nbsp;</td>
        <td>
          <label>
            <input type="text" name="username" id="textfield" />
            </label>
        </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td colspan="2"><label>Password</label>&nbsp;</td>
        <td>
          <label>
            <input type="password" name="password" id="textfield2" />
            </label>
        </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td colspan="2">&nbsp;</td>
        <td>
          <label>
            <input type="submit" name="button" id="button" value="Login" />
            </label>
        </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td colspan="2">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="5"><span style="color:#F00"><?php echo $message;  ?></span></td>
        <td>&nbsp;</td>
      </tr>

    </table></td>
  </tr>
</table>

adminloginvalidate.php

<?php
$username=$_POST["username"];
$password=$_POST["password"];

 $con=mysql_connect("localhost","root","");
mysql_select_db("student_management",$con);

$query="SELECT count(*) FROM administrator
where username='$username' and password='$password'";
$result=mysql_query($query);
while($row = mysql_fetch_array($result))
{   
$answer=$row[0];}

if($answer!=0){

session_start();
$_SESSION['username']=$username;
$_SESSION['state']="admin";
header("location:../../add admin users/add techer/addAdminterpage.php");
exit();
}else{
header("location:index.php?msg=your username password is incorrect");
exit();
}

?>

Recommended Answers

All 2 Replies

The posted msg may not exist. You can use isset to check if it does. If you change line 13 to the following:

$message = isset($_POST['msg']) ? $_POST['msg'] : '';

It will use the posted variable if it exists, or an empty string if it does not.

Thanks a lot..Now it works..:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.