3 Replies - 2028 Views - Last Post: 30 October 2011 - 02:53 PM Rate Topic: -----

#1 m@m  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 02-September 11

Undefined index error in php

Posted 30 October 2011 - 04:05 AM

I use below code for search and view employee profile.But i got Variable undefine error... how can i fix it ? here i have posted errors....

Errors
------------
1.Notice: Undefined index: uname in C:\wamp\www\P2011-001\StaffHandling\emp_profile.php on line 233
2.Notice: Undefined variable: image in C:\wamp\www\P2011-001\StaffHandling\emp_profile.php on line 300
3.Notice: Undefined variable: fname in C:\wamp\www\P2011-001\StaffHandling\emp_profile.php on line 335
4.Notice: Undefined variable: lname in C:\wamp\www\P2011-001\StaffHandling\emp_profile.php on line 336
5.Notice: Undefined variable: email in C:\wamp\www\P2011-001\StaffHandling\emp_profile.php on line 341
6.Notice: Undefined variable: address in C:\wamp\www\P2011-001\StaffHandling\emp_profile.php on line 346
7.Notice: Undefined variable: gender in C:\wamp\www\P2011-001\StaffHandling\emp_profile.php on line 355
8.Notice: Undefined variable: mobile in C:\wamp\www\P2011-001\StaffHandling\emp_profile.php on line 363
9.Notice: Undefined variable: land in C:\wamp\www\P2011-001\StaffHandling\emp_profile.php on line 369
10.Notice: Undefined variable: bod in C:\wamp\www\P2011-001\StaffHandling\emp_profile.php on line 376

FULL CODE HERE

<?php 
	$con=mysql_connect('localhost','root','');
	mysql_select_db('hms');
    
    
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Employee Profile</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="js/jquery.js" type="text/javascript"></script>
<script type="text/javascript" src="js/cufon-yui.js"></script>
<script type="text/javascript" src="js/georgia.js"></script>
<script type="text/javascript" src="js/cuf_run.js"></script>
<style type="text/css">
#container
{
	margin: 0 auto;
	width: 100%;
	background: #fff;
}

#header
{
	background: #ccc;
	padding: 20px;
}

#header h1 { margin: 0; }

#navigation
{
	float: left;
	width: 100%;
	background: #333;
}

#navigation ul
{
	margin: 0;
	padding: 0;
}

#navigation ul li
{
	list-style-type: none;
	display: inline;
}


#navigation li a
{
	display: block;
	float: left;
	padding: 5px 10px;
	color: #fff;
	text-decoration: none;
	border-right: 1px solid #fff;
}

#navigation li a:hover { background: #383; }

#content-container1
{
	float: left;
	width: 100%;
	background: #fff url(/wp-content/uploads/layout-three-liquid-background1.gif) repeat-y 20% 0;
}

#content-container2
{
	float: left;
	width: 100%;
	background: url(/wp-content/uploads/layout-three-liquid-background2.gif) repeat-y 80% 0;
}

#section-navigation
{
	float: left;
	width: 20%;
	padding: 20px 0;
	margin: 0 2%;
	display: inline;
}

#section-navigation ul
{
	margin: 0;
	padding: 0;
}

#section-navigation ul li
{
	margin: 0 0 1em;
	padding: 0;
	list-style-type: none;
}

#content
{
	float: left;
	width: 48%;
	padding: 20px 0;
	margin: 0 0 0 2%;
}

#content h2 { margin: 0; }

#aside
{
	float: right;
	width: 22%;
	padding: 20px 0;
	margin: 0 2% 0 0;
	display: inline;
}

#aside h3 { margin: 0; }

#footer
{
	clear: both;
	background: #ccc;
	text-align: right;
	padding: 20px;
	height: 1%;
}



</style>
<style type="text/css">

body {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	margin: 0;
	font-size: 80%;
	font-weight: bold;
	background: #FFF;
	}

h2 {
	font: bold 14px Verdana, Arial, Helvetica, sans-serif;
	color: #000;
	margin: 0px;
	padding: 0px 0px 0px 15px;
}
	
ul {
	list-style: none;
	margin: 0;
	padding: 0;
	}

img {
    border: none;
} 
/*- Menu 8--------------------------- */
	
#menu8 {
	width: 200px;
	margin: 10px;
	border-style: solid;
	border-color: #656556;
	border-size: 1px;
	border-width: 1px;
	}
	
#menu8 li a {
	height: 32px;
  	voice-family: "\"}\""; 
  	voice-family: inherit;
  	height: 24px;
	text-decoration: none;
	}	
	
#menu8 li a:link, #menu8 li a:visited {
	color: #656556;
	display: block;
	background:  url(menu8.gif);
	padding: 8px 0 0 20px;
	}
	
#menu8 li a:hover {
	color: #474739;
	background:  url(menu8.gif) 0 -32px;
	padding: 8px 0 0 20px;
	}
	
	


	
/*- Menu 10--------------------------- */
	
#menu10 {
	width: 200px;
	margin: 10px;
	}
	
#menu10 li a {
	height: 32px;
  	voice-family: "\"}\""; 
  	voice-family: inherit;
  	height: 24px;
	text-decoration: none;
	}	
	
#menu10 li a:link, #menu10 li a:visited {
	color: #4D4D4D;
	display: block;
	background:  url(menu10.gif);
	padding: 8px 0 0 10px;
	}
	
#menu10 li a:hover {
	color: #FF9834;
	background:  url(menu10.gif) 0 -32px;
	padding: 8px 0 0 10px;
	}
		

  </style>
  
</head>
<body>

<?php 
		
			$uname = $_POST['uname'];
			$sql = "SELECT * FROM emp WHERE uname = '$uname'";
			$result = mysql_query($sql);
			if (mysql_num_rows($result) > 0)
			{
				while ($row = mysql_fetch_array($result))
				{
					$fname = $row['fname'];
                    $lname = $row['lname'];
					$email = $row['email'];
					$address = $row['address_1'];
					$image = $row['image'];
                    $gender=$row['gender'];
                    $mobile=$row['tp_mobile'];
                    $land=$row['tp_lnd'];
                    $bod=$row['bod'];
                    
				}
            }
                  
		?>  

 
<div class="main">
  <div class="header">
    <div class="header_resize">
      <div class="logo"><h1></h1></div>
      
      
      <div class="clr"></div>
      <div class="search">
        <form id="form1" name="form1" method="post" action="emp_profile.php">
          <span>
          <input name="pid" type="text" class="keywords" id="textfield" maxlength="50"  />
          
          </span>
          <input name="b" type="image" src="images/search.gif" class="button" />
        </form>
      </div>
               <div class="menu">
        <ul>
          <!--
<li><a href="index.html" class="active">Home</a></li>
          <li><a href="services.html">Services</a></li>
          <li><a href="about.html"> About Us </a></li>
          <li><a href="contact.html"> Contact Us</a></li>
-->
        </ul>
      </div>
      
    </div>
    <div class="clr"></div>
  </div>
        <div class="clr"></div>
  
    <div class="body">
        <div class="body_resize">

        <form id="" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data"  accept-charset='UTF-8'> 
        <div id="container">

<fieldset >
	
	<div id="content-container1">
		<div id="content-container2">
         
			<div id="section-navigation">
				<img align="top"  width="175" height="200" src="emp_images/<?php echo $image; ?>"/>
                <div>
                  
                
                    <!--
<label>Patient Name : </label>

-->
<br />

               
                 
                 
    
     
 

     
 
 
     
     
     
     </div>
                
                
                
    
			</div>

			<div id="content" align="justify">
           
				
                
				<h2>
			    <label for="fname"> <?php echo $fname; ?></label> 
                <label for="lname"> <?php echo $lname; ?></label>
				</h2>
				<p>
                <label><b>Email:</b></label>
                <br />
                <label for="email"> <?php echo $email; ?></label>
				</p>
				<p>
                <label><b>Employee Address:</b></label>
                <br />
                <label > <?php echo $address; ?></label>
 
                    </p> 
 

 
                    <p>
                    <label><b>Gender:</b></label>
                    <br />
                <label > <?php echo $gender ?></label>
                </p> 
 
 

                    <p>
                    <label><b>Patient Mobile:</b></label>
                    <br />
                    <label > <?php echo $mobile ?></label>
                    </p>

                    <p>
                    <label><b>Patient Resident Number:</b></label>
                    <br />
                    <label > <?php echo $land ?></label>
                        </p>

			
					<p>
                    <label><b>Patient Current Status:</b></label>
                    <br />
                    <label > <?php echo $bod ?></label>
                        </p>
        	
				
		
                
		
	</div>
            
</div>
  </fieldset>    
     
      <div class="clr"></div>
      
      
    </div>
  </div>
  </form>

                <div class="footer">
                <div class="footer_resize">
                <p>&copy; P2011-001</p>
                </div>
                <div class="clr"></div>
                </div>
       
    </div>
    
</div>
</div>
</body>
</html>


<?php 
	mysql_close($con);
?>


Is This A Good Question/Topic? 0
  • +

Replies To: Undefined index error in php

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3512
  • View blog
  • Posts: 10,136
  • Joined: 08-June 10

Re: Undefined index error in php

Posted 30 October 2011 - 04:32 AM

thatís because on the initial page load, the form is not (canít be) submitted, hence $_POST is empty.
Was This Post Helpful? 1
  • +
  • -

#3 m@m  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 02-September 11

Re: Undefined index error in php

Posted 30 October 2011 - 06:00 AM

post in same page know ?

<form id="form1" name="form1" method="post" action="emp_profile.php">
265	          <span>

Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3512
  • View blog
  • Posts: 10,136
  • Joined: 08-June 10

Re: Undefined index error in php

Posted 30 October 2011 - 02:53 PM

line #291.

anyways, that doesnít change the fact that on initial page load there are no posted data.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1