Page 1 of 1

Error: undefined index

Posted: Thu Sep 17, 2009 12:42 am
by om.bitsian
hello friends
i am using wamp server 2.0i , there i have a php page in which line 80 and 81 are

80. $var=$_POST['psrnno'];
81. $radio=$_POST['RadioGroup1'];

when i run the page...its showing these errors
Notice: Undefined index: psrnno in C:\wamp\www\team-1\update\2.php on line 80

Notice: Undefined index: RadioGroup1 in C:\wamp\www\team-1\update\2.php on line 81

Re: Error: undefined index

Posted: Thu Sep 17, 2009 12:47 am
by dude81
Those variables are not present in the $_POST i.e. meaning those form which is posting, does not contain those variables that you are checking here.

Code: Select all

 
$var=$_POST['psrnno'];
$radio=$_POST['RadioGroup1'];
 
Try posting your form html code here.

Re: Error: undefined index

Posted: Thu Sep 17, 2009 12:53 am
by om.bitsian
<form action="" method="post" name="form1" class="style1" id="form1">
<p>
<label style="color:#000099">
<input type="radio" name="RadioGroup1" value="0" />
0 (Current employees)</label>
<br />
<label style="color:#000099">
<input type="radio" name="RadioGroup1" value="1" />
1 (Temperory Stopage of salary)</label>
<br />
<label style="color:#000099">
<input type="radio" name="RadioGroup1" value="2" />
2 (Permanent Deletion)</label>
<br />

for full code please find attached file

Re: Error: undefined index

Posted: Thu Sep 17, 2009 1:03 am
by dude81
Saw your attachment. You have two form codes declared in html. Remove one. Also you need to write code for $_POST after you check isset($_POST['submit']), not before it.

Re: Error: undefined index

Posted: Thu Sep 17, 2009 1:42 am
by om.bitsian
i have tested it....when i open the form its not showing the warning but when i press the submit button than its showing the same warning.....

Re: Error: undefined index

Posted: Thu Sep 17, 2009 2:09 am
by dude81
Remove comments from below code . I don't have table structure here. Neither Ill create one to test it. Please do a little debugging on if loops , the code would work

Code: Select all

 
<?php
session_start(); 
$_POST['psrn']=0;
$_SESSION['psrn_no']=$_POST['psrn'];
if(!isset($_POST['Submit']))
{?>
<script language="javascript">
function highlight(field)
{
field.focus();
field.select();
}
</script>
 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Employee Flag</title>
<style type="text/css">
<!--
.style1 {font-family: Arial, Helvetica, sans-serif}
-->
</style>
 
</head>
<body bgcolor="#cccccc" style="color:#000099">
<body bgcolor="#cccccc" text="#000099">
<hr style="color:#000099">
<h2 align="center" class="style1">EMPLOYEE FLAG</h2>
<hr style="color:#000099">
<form id="form1" name="form1" method="post" action="">
<span class="style1"><br>
<br>
<br>
</span>
<div align="left" class="style1" style="color:#000099"><b>Enter psrn number:</b>
    <br><br>
    <input type="text" name="psrnno"  onclick='highlight(this);'/> 
    <br>
    <br> 
  </div>
  <p class="style1">
 
<div align="left" style="color:#000099">
<span class="style1"><b>Enter Flag:</b>
</span>
  <p>
    <label style="color:#000099">
      <input type="radio" name="RadioGroup1" value="0" />
      0 (Current employees)</label>
    <br />
    <label style="color:#000099">
      <input type="radio" name="RadioGroup1" value="1" />
      1 (Temperory Stopage of salary)</label>
    <br />
    <label style="color:#000099">
      <input type="radio" name="RadioGroup1" value="2" />
      2 (Permanent Deletion)</label>
    <br />
    
    <br />
  </p>
  <label></label>
  <input type="submit" name="submit" value="Enter" style="width:70px"/>
&nbsp;&nbsp;<input type="button" name="Submit1" value="Back to Update Options" onclick='window.location="http://localhost/team-1/update/updateoptions.php"'/>
</div></form>
</body>
</html>
 
<?php
}
 
 
 
$var=$_SESSION["psrn_no"];
//require($_SERVER["DOCUMENT_ROOT"]."/config/config.php");
//$connection = mysql_connect($host, $user, $password) or die("error connecting");
//mysql_select_db('bits_sap') or die("cannot select database");
 
if(isset($_POST['submit']))
{
$var=$_POST['psrnno'];
 $radio=$_POST['RadioGroup1'];
   if(trim($_POST['psrnno']) == "")
   {
   die ("Please enter value for PSRN");
   }
   if(preg_match('/[^0-9]/', $var))
                             {
                                die ("Error: PSRN should be a numeric value.");
                                
                             }
 if ($_POST['psrnno']=="0")
header ('Location: http://localhost/team-1/update/2.php');
else{
    if (($_POST['RadioGroup1'] == "")&&($_POST['psrnno']!="")) 
    {
    die("Please enter the flag value.");
    }
if (($_POST['RadioGroup1'] != "")&&($_POST['psrnno']!="")) 
{
$query ="SELECT paymajor.FIRST_NAME FROM paymajor WHERE paymajor.PSRN=$var";
    //$result = @mysql_query($query, $connection) or die("o data");
$query2 ="SELECT paymajor.MIDDLE_NAME FROM paymajor WHERE paymajor.PSRN=$var";
    //$result2 = @mysql_query($query2, $connection) or die("o data");
$query3 ="SELECT paymajor.LAST_NAME FROM paymajor WHERE paymajor.PSRN=$var";
    //$result3 = @mysql_query($query3, $connection) or die("o data");
 
$old ="SELECT paymajor.FLAG FROM paymajor WHERE paymajor.PSRN=$var";
//$result4 = @mysql_query($old) or die("query failed") ;
 
//$result = @mysql_query($query) or die("query failed") ;
 
/*
 * if(mysql_num_rows($result))
{
$name=mysql_result($result,0,"FIRST_NAME");
$name2=mysql_result($result2,0,"MIDDLE_NAME");
$name3=mysql_result($result3,0,"LAST_NAME");
 
$old=mysql_result($result4,0,"FLAG");
$query = "UPDATE `paymajor` SET FLAG= '$radio' WHERE PSRN=$var";
$result = mysql_query($query, $connection) or die(mysql_error());*/
if ($result == 1)
{
echo "PSRN= ",$var, "&nbsp&nbsp&nbsp Name= ",$name," ",$name2," ",$name3,"&nbsp&nbsp&nbsp&nbsp Old Flag= ",$old, "&nbsp&nbsp&nbsp&nbsp New Flag= ", $radio;
}
/*
else
echo $var."does not exist";
}*/
else 
echo "PSRN ",$var," does not exist";
    }
  }
}
 
?>
 
 

Re: Error: undefined index

Posted: Thu Sep 17, 2009 4:54 am
by om.bitsian
thank you....dude81 its working for me