title: Undefined index in PHP while saving edited form
body: <p>When I delete it works fine.
  When I cancel also it works fine.
  But when I edit and click on save after edit I get the message "Undefined index: search in ".
  Data gets saved though.
  How do I fix this.</p>
  
  <p>Code is :</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
      &lt;/head&gt;
  &lt;body&gt;  
  &lt;?php
      $page='search.php';
      mysql_connect("localhost","root","") or die (mysql_error());
      mysql_select_db("list") or die (mysql_error());
  
      if(empty($_POST) === false)
      {
  
          if ($_POST['search'] == 'search')
          {
  
              $data=$_POST['criteria']; 
              if (empty($data) === true)
              {
                  echo 'Please enter some text!!&lt;br/&gt;';
              } 
              else
              {
                  $get=mysql_query("SELECT SRNO, fname, lname, phone, email, address, comments from names where fname='" . mysql_real_escape_string($data) . "'");
                  if (mysql_num_rows($get)==0) 
                      {
                          echo 'There are no search results!!';
                      }
                          else
                      {
                          echo '&lt;table border=0 cellspacing=25 cellpadding=1&gt;';
                          echo'&lt;tr&gt;&lt;th&gt;Sr. No&lt;/th&gt;&lt;th&gt;First Name&lt;/th&gt;&lt;th&gt;Last Name&lt;/th&gt;&lt;th&gt;Phone No&lt;/th&gt;&lt;th&gt;E-mail&lt;/th&gt;&lt;th&gt;Address&lt;/th&gt;&lt;th&gt;Comments!!&lt;/th&gt;&lt;th&gt;Modify&lt;/th&gt;&lt;th&gt;Delete!&lt;/th&gt;&lt;/tr&gt;';      
                          while($get_row=mysql_fetch_assoc($get))
                              {
                                  echo '&lt;tr&gt;&lt;td&gt;'.$get_row['SRNO'].'&lt;/td&gt;&lt;td&gt;'.$get_row['fname'].'&lt;/td&gt;&lt;td&gt;'.$get_row['lname'].'&lt;/td&gt;&lt;td&gt;'.$get_row['phone'].'&lt;/td&gt;&lt;td&gt;'.$get_row['email'].'&lt;/td&gt;&lt;td&gt;'.$get_row['address'].'&lt;/td&gt;&lt;td&gt;'.$get_row['comments'].'&lt;/td&gt;&lt;td&gt;&lt;a href="search.php?edit='.$get_row['SRNO'].'"&gt;Edit&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&lt;a href="search.php?delete='.$get_row['SRNO'].'"&gt;Delete&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;';
  
                              }
                          echo '&lt;/table&gt;';
  
                      }
              }
          }
  
          else if ($_POST['save']== 'save')
          {
  
              $count=0;
              $fname= $_POST['fname'];
              $lname= $_POST['lname'];
              $srno=  $_POST['SRNO'];
              $address=$_POST['address'];
              $comments=$_POST['comments'];
              $email=$_POST['email'];
              $phone=$_POST['phone'];
  
                  if (empty($lname) === true || empty($fname) === true || empty($address) === true || empty($comments) === true || empty($email) === true || empty($phone) === true) 
                  {
                      echo '&lt;h3&gt;All fields are mandatory&lt;/h3&gt;';
  
                  }
                  else
                  {
                          if (filter_var($email,FILTER_VALIDATE_EMAIL) === false)
                          {
                              echo '&lt;h3&gt;This is not a valid e-mail address.&lt;/h3&gt;&lt;br /&gt;';
                              $count=$count+1;
                          }
                          if (ctype_alpha($fname) === false || ctype_alpha($lname) === false)
                          {
                              echo '&lt;h3&gt;Name should contain character only!&lt;/h3&gt;&lt;br /&gt;';
                              $count=$count+1;
                          }
                          if( !is_numeric($phone) ) 
                          {
                                  echo '&lt;h3&gt;Please enter a valid phone number&lt;/h3&gt;&lt;br /&gt;';
                                  $count=$count+1;
                          }
                          if ($count==0)
                          {
                              if(isset($_GET['edit']))
                                  {
                                      mysql_query('update names set fname="'.$fname.'", lname="'.$lname.'", address="'.$address.'", comments="'.$comments.'", email="'.$email.'", phone="'.$phone.'"  where SRNO="'.$srno.'"');   
  
                                  } 
                                  else if(isset($_GET['add']))
                                      {
                                          mysql_query("INSERT INTO names (fname,lname,phone,email,comments,address) VALUES ('$fname', '$lname','$phone','$email','$comments','$address')");
                                      }
  
                              //header('Location:'.$page);
                          }
  
                  }
          }
      }   
              //else if
          /*
          if(mysql_num_rows($getf) == 0)
          {
              $getel=mysql_query('SELECT SRNO, fname, lname, phone, email, address, comments from names where lname='.$_GET['$data']));
  
          }*/
  
  
  
          if(isset($_GET['delete']))
          {
              mysql_query('DELETE from names where SRNO='.mysql_real_escape_string((int)$_GET['delete']));
  
          }
  
          if(isset($_GET['edit']))
          {
              $getedit=mysql_query('SELECT SRNO, fname, lname, phone, email, address, comments from names where SRNO='.mysql_real_escape_string((int)$_GET['edit']));
  
              echo '&lt;table border=0&gt;';
              while ($get_row=mysql_fetch_assoc($getedit))
                  {
                      echo '&lt;form method="POST" action=""&gt;';
  
                      echo '&lt;tr&gt;&lt;td&gt;Sr.No:&lt;/td&gt;&lt;td&gt;&lt;input type="text" value='.$get_row['SRNO'].' name="SRNO" readonly="readonly"&gt;&lt;/td&gt;&lt;/tr&gt;';
                      echo '&lt;tr&gt;&lt;td&gt;First Name:&lt;/td&gt;&lt;td&gt;&lt;input type="text" value='.$get_row['fname'].' name="fname"&gt;&lt;/td&gt;&lt;/tr&gt;';
                      echo '&lt;tr&gt;&lt;td&gt;Last Name:&lt;/td&gt;&lt;td&gt;&lt;input type="text" value='.$get_row['lname'].' name="lname"&gt;&lt;/td&gt;&lt;/tr&gt;';
                      echo '&lt;tr&gt;&lt;td&gt;Phone No:&lt;/td&gt;&lt;td&gt;&lt;input type="text" value='.$get_row['phone'].' name="phone"&gt;&lt;/td&gt;&lt;/tr&gt;';
                      echo '&lt;tr&gt;&lt;td&gt;E-mail address:&lt;/td&gt;&lt;td&gt;&lt;input type="text" value='.$get_row['email'].' name="email"&lt;/td&gt;&lt;/tr&gt;';
                      echo '&lt;tr&gt;&lt;td&gt;Address:&lt;/td&gt;&lt;td&gt;&lt;textarea name="address" rows=4&gt;'.$get_row['address'].'&lt;/textarea&gt;&lt;/td&gt;&lt;/tr&gt;';
                      echo '&lt;tr&gt;&lt;td&gt;Comments:&lt;/td&gt;&lt;td&gt;&lt;textarea name="comments" rows=4&gt;'.$get_row['comments'].'&lt;/textarea&gt;&lt;/td&gt;&lt;/tr&gt;';
                      echo '&lt;tr&gt;&lt;td&gt;&lt;input type="submit" name="save" value="save"&gt;&lt;/td&gt;&lt;td&gt;&lt;a href="search.php"&gt;Cancel&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;';
                      echo '&lt;/form&gt;';                                 
                  }
              echo '&lt;/table&gt;';
  
          }
  
              echo '&lt;form action="" method="post"&gt;';  
              echo '&lt;input type="text" name="criteria"&gt;';
              //echo '&lt;input type="hidden" name="form" value="search"&gt;';
              echo '&lt;input type="submit" value="search" name="search"&gt;';
              echo '&lt;/form&gt;';
  
   echo '&lt;br /&gt;&lt;a href="index.php"&gt;Home&lt;/a&gt;';
  ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>