title: Weird error when updating database using php
body: <p>I have a weird problem in which if I delete the line <strong><em><code>Type doctor name &lt;input type="text" name="new_Doctor_name" value="&lt;?php echo $row1[3]; ?&gt;" &gt;&lt;br /&gt;</code></em></strong>, I cannot update my records and get the notice  <strong><em>Undefined variable: row1</em></strong>. However, if I keep this line, which I copy from another table, I can update just fine.</p>
  
  <p>Please explain this. Any help will be highly appreciated.</p>
  
  <pre><code>&lt;?php
  
  include_once('Connect.php');
              if( isset($_GET['edit1']) )
              {
                  $id = $_GET['edit1'];
                  $res1= mysql_query("SELECT * FROM department WHERE Dept_name='$id'");
                  $row1= mysql_fetch_array($res1);
              }
  
              if( isset($_POST['new_Doctor_name']) )
              {
                  $id                 = $_POST['id'];
                  $new_Dept_name      = $_POST['new_Dept_name'];
                  $new_Ward           = $_POST['new_Ward'];
                  $sql1                = "UPDATE department SET Dept_name='$new_Dept_name', Ward='$new_Ward' WHERE Dept_id='$id'";
                  $res2                = mysql_query($sql1) or die("Could not Update".mysql_error());
                  echo "&lt;meta http-equiv='refresh' content='0;url=Department_viewtable.php'&gt;";
              }   
              var_dump($row1);
  ?&gt;
  
  &lt;FORM ACTION="Department_dmod.php" METHOD="post"&gt; 
  &lt;input type="hidden" name="id" value="&lt;?php echo $id; ?&gt;" /&gt;
  ***Type doctor name &lt;input type="text" name="new_Doctor_name" value="&lt;?php echo $row1[3]; ?&gt;" &gt;&lt;br /&gt;***
  Type Department Name &lt;input type="text" name="new_Dept_name" value="&lt;?php echo $row1[1]; ?&gt;" &gt;&lt;br /&gt;
  Type Department Ward &lt;input type="text" name="new_Ward" value="&lt;?php echo $row1[2]; ?&gt;" &gt;
  &lt;INPUT TYPE="SUBMIT" NAME="UPDATE" VALUE="UPDATE"&gt; 
  &lt;p&gt;&lt;a href=Department_viewtable.php&gt;Back to the Department table&lt;/a&gt;&lt;/p&gt;
  &lt;p&gt;&lt;a href=Main_Menu.php&gt;Back to Main menu&lt;/a&gt;&lt;/p&gt;
  &lt;/FORM&gt;
  </code></pre>