title: Undefined offset: error in $row[] php
body: <p>I get a "Undefined offset: 1 " , " Undefined offset: 2 " ...etc error when i execute the following transportreg_edit_n.php</p>
  
  <p>places where error points to are highlighted...</p>
  
  <p>"I earlier got undefined variable row" error then i initialized it as $row="" ; then i got this.. 
  What should i do to get rid of this?</p>
  
  <p>I'm not sure if i'm using the isset(.....) property correctly because i didn't come to error checking of that point still :) if so bear with my novice mistakes :) tnx a lot in advance.   </p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;Edit Page&lt;/title&gt;
  
  &lt;style type="text/css"&gt;
  body,td,th {
      font-family: Arial, Helvetica, sans-serif;
      font-size: 16px;
      text-align: left;
  }
  body {
          background: url(Image/bg.jpg) no-repeat center center fixed; 
          -webkit-background-size: cover;
          -moz-background-size: cover;
          -o-background-size: cover;
          background-size: cover;
  }
  
  &lt;/style&gt;
  &lt;link href="CSS/transportreg_editStyleSheet.css" rel="stylesheet" type="text/css" /&gt;
  &lt;/head&gt;
  
  
  
  &lt;?php
  
          $dbhost="localhost";
          $dbuser="root";
          $dbpass="rootout";
          $dbdb="test";
  
  
          $connect = mysql_connect($dbhost,$dbuser,$dbpass);
          if (!$connect)
          {
              echo "Failed To Connect To MySql".mysql_error();
              echo "&lt;br /&gt;&lt;br /&gt;&lt;a href='transportreg.php'&gt;Go Back &lt;/a&gt;";
          }
  
  
          $db = mysql_select_db($dbdb,$connect);
          if (!$db)
          {
              echo "Failed To Connect To The Database".mysql_error();
              echo "&lt;br /&gt;&lt;br /&gt;&lt;a href='transportreg.php'&gt;Go Back &lt;/a&gt;";
          }
  
  
          $row = ""; //added this because of undefined variable row error
  
  
          if(isset($_GET['edit']))
          {
              $id = $_GET['edit'];
              $sql = "SELECT * FROM transportpublic WHERE transportpublicid='$id' ";
              $res = mysql_query($sql)or die($sql."&lt;br/&gt;&lt;br/&gt;".mysql_error());
              $row = mysql_fetch_array($res,MYSQL_BOTH);
          }
  
          if(isset($_POST['edittxttravelType_public'],$_POST['edittxtCostPerKm_public'],$_POST['edittxtAddress_public'],$_POST['edittxtPhoneNumber1_public'],$_POST['edittxtweblink_public'],$_POST['edittxtDescription_public']))
          {
              $id = $_POST['edittxtid_public'];
              $new_txttravelType_public = $_POST['edittxttravelType_public'];
              $new_txtCostPerKm_public = $_POST['edittxtCostPerKm_public'];
              $new_txtAddress_public = $_POST['edittxtAddress_public'];
              $new_txtPhoneNumber1_public = $_POST['edittxtPhoneNumber1_public'];
              $new_txtweblink_public = $_POST['edittxtweblink_public'];
              $new_txtDescription_public = $_POST['edittxtDescription_public'];
  
              $sql = "UPDATE transportpublic SET transportType='$new_txttravelType_public'  AND costPerKm='$new_txtCostPerKm_public'  AND address='$new_txtAddress_public'  AND teleNo='$new_txtPhoneNumber1_public'  AND webLink='$new_txtweblink_public'  AND description='$new_txtDescription_public'  WHERE transportpublicid ='$id' ";
  
              $res = mysql_query($sql) or die("Error Occured Update Unseccessful! ".mysql_error());
  
  
              echo "&lt;br /&gt;&lt;a href='transportreg_showdata.php'&gt;View Current Data&lt;/a&gt;";
  
          }
  
  
  ?&gt;
  
  &lt;body&gt;
  &lt;form id="form1" name="form1" method="post" action="transportreg_edit_n.php"&gt;
    &lt;table width="597" border="0" align="center" cellpadding="0"&gt;
      &lt;tr&gt;
        &lt;th colspan="2" bgcolor="#000000" class="mainTitle" scope="row"&gt;Edit Form&lt;/th&gt;
      &lt;/tr&gt;
      &lt;tr bgcolor="#c1e9ea"&gt;
        &lt;td width="324" scope="row"&gt;&lt;blockquote&gt;
          &lt;p&gt;&lt;span class="classlabels"&gt;Transportation Type/Name :&lt;/span&gt;&lt;/p&gt;
        &lt;/blockquote&gt;&lt;/td&gt;
        &lt;td width="270"&gt;
        &lt;label for="edittxttravelType_public"&gt;&lt;/label&gt;
  
        //here $row[1] causes the error "Undefined offset: 1"
  
       &lt;input name="edittxttravelType_public" type="text" value="&lt;?php echo $row[1]; ?&gt;" id="edittxttravelType_public2" size="45" maxlength="60" /&gt;
  
        //here $row[0] causes an error "Undefined offset: 0"
  
       &lt;input name="edittxtid_public" type="hidden" value="&lt;?php echo **$row[0]**; ?&gt;" id="edittxttravelType_public" size="45" maxlength="60" /&gt;
       &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr bgcolor="#dbf4f6"&gt;
        &lt;td scope="row"&gt;&lt;blockquote&gt;
          &lt;p&gt;Cost per kilometer :&lt;/p&gt;
        &lt;/blockquote&gt;&lt;/td&gt;
        &lt;td&gt;
        &lt;label for="edittxtCostPerKm_public"&gt;&lt;/label&gt;
  
         //here $row[2] causes an error "Undefined offset: 2"
  
        &lt;input name="edittxtCostPerKm_public" value="&lt;?php echo $row[2]; ?&gt;" type="text" id="edittxtCostPerKm_public" size="45" maxlength="60" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td bgcolor="#c1e9ea" scope="row"&gt;&lt;blockquote&gt;Address :&lt;/blockquote&gt;&lt;/td&gt;
        &lt;td bgcolor="#c1e9ea"&gt;
        &lt;label for="edittxtAddress_public"&gt;&lt;/label&gt;
  
       //here $row[3] causes an error "Undefined offset: 3"
  
      &lt;textarea name="edittxtAddress_public" id="edittxtAddress_public" cols="32" rows="3"&gt;&lt;?php echo $row[3]; ?&gt; &lt;/textarea&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr bgcolor="#dbf4f6"&gt;
        &lt;td bgcolor="#dbf4f6" scope="row"&gt;&lt;blockquote&gt;Telephone Number :&lt;/blockquote&gt;&lt;/td&gt;
        &lt;td&gt;
        &lt;label for="edittxtPhoneNumber1_public"&gt;&lt;/label&gt;
  
      //here $row[4] causes an error "Undefined offset: 4"
  
      &lt;input name="edittxtPhoneNumber1_public" type="text"  value="&lt;?php echo $row[4]; ?&gt;" id="edittxtPhoneNumber1_public" size="45" maxlength="15" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr bgcolor="#c1e9ea"&gt;
        &lt;td bgcolor="#c1e9ea" scope="row"&gt;&lt;blockquote&gt;Official WebSite Link :&lt;/blockquote&gt;&lt;/td&gt;
        &lt;td&gt;
        &lt;label for="edittxtweblink_public"&gt;&lt;/label&gt;
  
     //here $row[5] causes an error "Undefined offset: 5"
  
      &lt;input name="edittxtweblink_public" type="text" value="&lt;?php echo $row[5]; ?&gt;" id="edittxtweblink_public" size="45" maxlength="300" /&gt;
  
       &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr bgcolor="#dbf4f6"&gt;
        &lt;td scope="row"&gt;&lt;blockquote&gt;Brief  Description :&lt;/blockquote&gt;&lt;/td&gt;
        &lt;td&gt;&lt;label for="edittxtDescription_public"&gt;&lt;/label&gt;
  
  
      //here $row[6] causes an error "Undefined offset: 6"
  
      &lt;textarea name="edittxtDescription_public" id="edittxtDescription_public" cols="32" rows="10"&gt;&lt;?php echo $row[6]; ?&gt;&lt;/textarea&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr bgcolor="#dbf4f6"&gt;
        &lt;td colspan="2" bgcolor="#c1e9ea" scope="row"&gt;&lt;blockquote&gt;
          &lt;blockquote&gt;
            &lt;blockquote&gt;
              &lt;blockquote&gt;
                &lt;blockquote&gt;
                  &lt;blockquote&gt;
                    &lt;p&gt;
                      &lt;input name="btnupdatet_public" type="submit" class="submit" id="btnupdatet_public" value="Update" /&gt;
                    &lt;/p&gt;
                  &lt;/blockquote&gt;
                &lt;/blockquote&gt;
              &lt;/blockquote&gt;
            &lt;/blockquote&gt;
          &lt;/blockquote&gt;
        &lt;/blockquote&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr bgcolor="#dbf4f6"&gt;
        &lt;td colspan="2" bgcolor="#c1e9ea" scope="row"&gt;&lt;table width="601" border='0' bordercolor='#000000' class="tb"&gt;
                    &lt;tr&gt; 
                        &lt;td width="340" height="20"&gt;&lt;a href='transportreg_showdata.php'&gt;View Updated Public Transportation Data&lt;/a&gt;
                        &lt;/td&gt;
                        &lt;td width="272"&gt;&lt;a href='transportreg.php'&gt;Go Back To Registration Page&lt;/a&gt;
                        &lt;/td&gt;
        &lt;/table&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
    &lt;p&gt;&amp;nbsp;&lt;/p&gt;
    &lt;p&gt;&amp;nbsp;&lt;/p&gt;
  &lt;/form&gt;
  &lt;?php
          mysql_close($connect);
  ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>