Author Topic: Getting Notice: Undefined index:  (Read 166 times)

prasun1519

  • New Member
  • *
  • Posts: 2
  • Karma: 0
    • View Profile
Getting Notice: Undefined index:
« on: March 16, 2012, 02:44:52 PM »
Hi

I am getting following notices in the following php code

Notice: Undefined index: who in C:\websites\return_submission\index.php on line 188

Notice: Undefined index: who in C:\websites\return_submission\index.php on line 192
PHP Code: [Select]

<?php 
session_start
();
ob_start();
include 
'connection.php';
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8">
<link href="CSS/jute_stylesheet.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
</head>

<body class="bg">
<script language="javascript" type="text/javascript">
//ajax code

function showCom(str)
{
function getobj()
{
   var xmlhttp = null;
   // I think the issue has something to do with this area of code... (1)
   
   if (window.ActiveXObject) { // IE
      try {
         xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
         try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
         } catch (e) {}
      }
   }
   else if (window.XMLHttpRequest) { // Mozilla, Safari,...
      xmlhttp = new XMLHttpRequest();
      if (xmlhttp.overrideMimeType) {
         xmlhttp.overrideMimeType('text/xhtml');
      }
   } 
   if (xmlhttp == null) {
      alert('Cannot create XMLHTTP instance');
        } 
return xmlhttp;      
}

	
	
xmlhttp=getobj();
var url="getcom.php";
url=url+"?q="+str;
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
//alert(q);
xmlhttp.send(null);

function stateChanged()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
  {

   document.getElementById("outputcompany").innerHTML=xmlhttp.responseText;
  }
}
}
//javascript functions
function disSelect()
{
  document.login.state.disabled=true;
  document.login.company.disabled=true;
  document.login.factory.disabled=true;
  return null;
}
function select1()
{
  document.login.state.disabled=false;
  document.login.company.disabled=false;
  document.login.factory.disabled=false;
  return null;
}


function valid()
{
if(document.getElementById('r2').checked==true)

var sta = document.login.state.selectedIndex;

 if(sta ==0)
 {
   
	
alert("you have to select your state");
   
	
document.login.state.focus();
   
	
return false;
 }
 
 if(document.login.user_name.value.search(/\S/) == -1)
   {
   
	
alert("you have to give your user name");
   
	
document.login.user_name.focus();
   
	
return false;
   }
   if(document.login.pwd.value.search(/\S/) == -1)
   {
   
	
alert("you have to give your password");
   
	
document.login.pwd.focus();
   
	
return false;
   }
}
else
{
if((document.login.who[0].checked == false) && (document.login.who[1].checked == false))
   {
   alert("you have to choose any user");
   return false;
   }

   if(document.login.user_name.value.search(/\S/) == -1)
   {
   
	
alert("you have to give your user name");
   
	
document.login.user_name.focus();
   
	
return false;
   }
   if(document.login.pwd.value.search(/\S/) == -1)
   {
   
	
alert("you have to give your password");
   
	
document.login.pwd.focus();
   
	
return false;
   }
}
}
</script>
<?php
$sql
="SELECT * FROM company";
$res=mysql_query($sql);

?>
<table width="100%" border="0">
  <tr> 
    <td height="23" colspan="2"> 
      <?php include 'header.php';?>
    </td>
  </tr>
  <tr> 
    <td height="23" colspan="2" class="marquee"> <marquee behavior="scroll">
      <em><font size="+2">Online Return Form Submission System </font></em> </marquee> </td>
  </tr>
  <tr> 
    <td height="29" colspan="2"><div align="right"><strong></strong></div></td>
  </tr>
  <tr> 
    <td width="34%" height="345"> 
      <?php include 'left.php';?>
    </td>
    <td width="66%"> <div align="center"> 
        <form action="" name="login" id="login" method="post" enctype="multipart/form-data">
          <p><strong>All fields marked with <span class="style1">*</span> are 
            mandatory </strong></p>
          <table width="100%" border="0">
            <?php
	
	
  if(isset(
$_SESSION['msg']))
	
	
  {
	
	
  
?>
            <tr> 
              <td height="30" colspan="4"> 
                <?php
	
	
	
  echo 
$_SESSION['msg'];
	
	
	
  unset (
$_SESSION['msg']);
	
	
	
  
?>
              </td>
            </tr>
            <?php
	
	
	
}
	
	
	
?>
            <tr> 
              <td height="30" colspan="4"> <div align="left"><strong><font face="Arial, Helvetica, sans-serif">User 
                  Login</font></strong></div></td>
            </tr>
            <tr> 
              <td width="29%"><input type="radio" name="who" id="r1" value="jute_commissioner" onClick="javascript:disSelect();">
                Jute Commissioner </td>
              <td width="7%">&nbsp;</td>
              <td colspan="2"><input type="radio" name="who" id="r2" value="Others" onClick="javascript:select1();">
                Others </td>
            </tr>
            <?php
	
	
	
if(
$_POST['who'] == 'jute_commissioner')
	
	
	
{
	
	
	
   
login1();
	
	
	
}
	
	
	
elseif(
$_POST['who'] == 'Others')
	
	
	
{
	
	
	
   
login2();
	
	
	
}
	
	
	
?>
            <tr> 
              <td>Select your State <span class="style1">*</span></td>
              <td><strong><font size="+2">:</font></strong></td>
              <td colspan="2"><select name="state" onChange="javascript:showCom(this.value)">
                  <option value="0">Select state</option>
                  <option value="as_1">Assam</option>
                  <option value="an_1">Andhra Pradesh</option>
                  <option value="tr_1">Tripura</option>
                  <option value="ut_1">Uttar Pradesh</option>
                  <option value="wb_1">West Bengal</option>
                </select></td>
            </tr>
             <tr> 
              <td>Company</td>
              <td><strong><font size="+2">:</font></strong></td>
              <td colspan="2" id="" ><!--<select name="company"  onBlur="javascript:showFact(this.value)" id="outputcompany" >
	
	
	
 
	
	
	
  </select>---><div id="outputcompany"></div></td>
            </tr>
            <tr> 
              <td>Factory</td>
              <td><strong><font size="+2">:</font></strong></td>
              <td colspan="2"  id=""><!--<select name="Factory" id="outputfactory"  >
	
	
	
  <option>select</option>
	
	
	
  </select>---><div id="outputfactory"></div></td>
            </tr>
            <tr> 
              <td>User Name <span class="style1">* </span></td>
              <td><font size="+2"><strong>:</strong></font></td>
              <td colspan="2"><input type="text" name="user_name"></td>
            </tr>
            <tr> 
              <td>Password <span class="style1">*</span> </td>
              <td><strong><font size="+2">:</font></strong></td>
              <td colspan="2"><input name="pwd" type="password" size="30" maxlength="20"></td>
            </tr>
            <tr> 
              <td height="32" colspan="3"> <div align="right"> 
                  <input type="submit" name="Submit" value="Submit" onClick="return valid();">
                </div></td>
              <td width="64%" height="32"><input type="reset" name="Submit2" value="Reset" align="left"></td>
            </tr>
          </table>
        </form>
      </div></td>
  </tr>
  <tr> 
    <td height="25" colspan="2"><?php include 'bottom.htm';?></td>
  </tr>
</table>
</body>
</html>
<?php
function login1()
{
	
$user_name=trim($_REQUEST['user_name']);
	
$pwd=trim($_REQUEST['pwd']);
	
$sql2 "SELECT * FROM jute_comm WHERE jc_username='$user_name' and jc_pwd='$pwd'";
	
$res2 mysql_query($sql2);
	

	
if(
mysql_num_rows($res2) > 0)
	
{
	
	
$row2 mysql_fetch_array($res2);
	
	
$_SESSION['USERID'] = $row2['id'];
	
	
header("location:login_jute.php");
	
}
	
else
	
{
	
	
$_SESSION['msg'] = "Wrong username or password.";
	
	
header("location:index.php");
	
}
}
function 
login2()
{
	
$user_name=trim($_REQUEST['user_name']);
	
$pwd=trim($_REQUEST['pwd']);
	
$company=$_REQUEST['company'];
    
$sql3 "SELECT * FROM factory WHERE fac_username=('$user_name') and fac_pwd=('$pwd')";
    
$res3 mysql_query($sql3);
	
if(
mysql_num_rows($res3) > 0)
	
{
	
	
$row3 mysql_fetch_array($res3);
	
	
$_SESSION['USERID'] = $row3['com_id'];
	
	
if(
$_SESSION['USERID']==$company)
	
	
header("location:login_mill.php");
	
	
else
	
	
echo
"Invalid User id or Password with respect to company";
	
}
	
else
	
{
	
	
$_SESSION['msg'] = "Wrong username or password.";
	
	
header("location:index.php");
	
}
}
?>

<script language="javascript" type="text/javascript">
//ajax code
var xmlhttp;
function showFact(str)
{
function getobj(){
	
if(window.XMLHttpRequest){
	
	
//alert("You are not using MSIE 5, 6");
	
	
return new XMLHttpRequest();
	
	
	
	
	
	
	
}
	
else if(window.ActiveXObject){
	
	
//alert("You are using MSIE 5,6");
	
	
return new ActiveXObject("Microsoft.XMLHTTP");
	
	
	
	
	
	
	
	
}
	
else
	
	
return null;
	
	
	
	
}
xmlhttp=getobj();
var url="getfact.php";
url=url+"?f="+str;

xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
function stateChanged()
{
if (xmlhttp.readyState==4)
  {

   document.getElementById("outputfactory").innerHTML=xmlhttp.responseText;
  }
}
}

</script>



Can anybody let me know where I am doing mistake?

Thanks in advance.

Prasun

ErnieAlex

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1847
  • Karma: 32
    • View Profile
Re: Getting Notice: Undefined index:
« Reply #1 on: March 16, 2012, 03:21:23 PM »
And, which line is 188 and 192???

prasun1519

  • New Member
  • *
  • Posts: 2
  • Karma: 0
    • View Profile
Re: Getting Notice: Undefined index:
« Reply #2 on: March 17, 2012, 05:49:38 AM »
It seems that the problem is with the lines:

PHP Code: [Select]

<?php
	
	
	
if(
$_POST['who'] == 'jute_commissioner')
	
	
	
{
	
	
	
   
login1();
	
	
	
}
	
	
	
elseif(
$_POST['who'] == 'Others')
	
	
	
{
	
	
	
   
login2();
	
	
	
}
	
	
	
?>

ErnieAlex

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1847
  • Karma: 32
    • View Profile
Re: Getting Notice: Undefined index:
« Reply #3 on: March 17, 2012, 12:27:01 PM »
Not sure, your code looks fine.  But, in PHP, usually you define your functions before you use them.
So, perhaps just moving the functions to the top of the page might fix this.

In Javascript it does not matter where you put your functions, but, PHP seems to like them defined before using them.  Try that and let us know...