title: Error: Notice: undefined index and creates null data when first opens page
body: <p>The follweing code IS working (it sends the data to the database). But I'm getting the "Notice: undefined index" as soon as I open the page and also it creates a null line (I mean, onde null value for each field) in the database. If I fill in the fields and submit it will work and they will be saved in the database alright, though. I think I need a code that will tell "submit" not to send data to the database it empty. What code is that? i'm not familiar with mysqli.</p>
  
  <pre><code>&lt;?php
  $con=mysqli_connect("localhost","root","","activitytest1");
  
  if (mysqli_connect_errno())
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
  
  $sql="INSERT INTO activitytest1 (type, description, author, outcome, pre, whileact, postact, path, books, grouping, time)
  VALUES
  ('$_POST[type]','$_POST[description]','$_POST[author]','$_POST[outcome]','$_POST[pre]','$_POST[whileact]','$_POST[postact]','$_POST[path]','$_POST[books]','$_POST[grouping]','$_POST[time]')";
  
  if (!mysqli_query($con,$sql))
    {
    die('Error: ' . mysqli_error($con));
    }
  $result = mysqli_query($con,"SELECT * FROM activitytest1");
  
  while($row = mysqli_fetch_array($result))
    {
    echo "&lt;br/&gt;
  
  &lt;table width='909' border='1' align='center' cellpadding='5' cellspacing='0'&gt;
    &lt;tr&gt;
      &lt;td width='125'&gt;" . $row['type'] .  "&lt;/th&gt;
      &lt;td width='680'&gt;" . $row['description'] .  "&lt;/th&gt;
      &lt;td width='120'&gt;" . $row['author'] .  "&lt;/th&gt;
    &lt;/tr&gt;&lt;/table&gt; &lt;br/&gt;" . $row['pre'] .  "&lt;br/&gt;" . $row['whileact'] .  "&lt;br/&gt;" . $row['postact'] .  "&lt;br/&gt;" . $row['outcome'] .  "&lt;br/&gt;" . $row['path'] . "&lt;br/&gt;" . $row['books'] .  "&lt;br/&gt;" . $row['grouping'] .  "&lt;br/&gt;" . $row['time'] . "&lt;hr size='1'/&gt;";
    }
  
  mysqli_close($con);
  ?&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;Test 1&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;br&gt;
  &lt;table width="909" border="1" align="center" cellpadding="5" cellspacing="0"&gt;
    &lt;tr&gt;
      &lt;th width="125" scope="col"&gt;Type&lt;/th&gt;
      &lt;th width="680" scope="col"&gt;Description&lt;/th&gt;
      &lt;th width="120" scope="col"&gt;Author&lt;/th&gt;
    &lt;/tr&gt;&lt;/table&gt;
    &lt;br&gt;
  &lt;form action="index.php" method="POST"&gt;
  
  &lt;table width="909" border="1" align="center" cellpadding="5" cellspacing="0"&gt;
       &lt;td width="125"&gt;&lt;label&gt;
  
       &lt;/label&gt;
         &lt;select name="type" id="type" onChange="display(this,'Task','Semi-task','Practice','Exercise','Lead-in');"&gt;
           &lt;option value="Unselected" selected="selected"&gt;Choose one:&lt;/option&gt;
           &lt;option value="Task"&gt;Task&lt;/option&gt;
           &lt;option value="Semi-task"&gt;Semi-task&lt;/option&gt;
           &lt;option value="Practice"&gt;Practice&lt;/option&gt;
           &lt;option value="Exercise"&gt;Exercise&lt;/option&gt;
           &lt;option value="Lead-in"&gt;Lead-in&lt;/option&gt;
           &lt;option value="Game"&gt;Game&lt;/option&gt;
           &lt;option value="Video"&gt;Video&lt;/option&gt;
           &lt;option value="Song"&gt;Song&lt;/option&gt;
           &lt;option value="Mimio"&gt;Mimio&lt;/option&gt;
           &lt;option value="Other"&gt;Other&lt;/option&gt;
         &lt;/select&gt;&lt;/td&gt;
      &lt;td width="680"&gt;&lt;div id="Semi-task" style="display: none;"&gt;
        Pre:&lt;br&gt;
      &lt;/div&gt;
          &lt;div id="Exercise"  style="display: none;"&gt;whileact:&lt;/div&gt;
          &lt;br&gt;
          &lt;div id="Practice" style="display: none;"&gt;
        Post:&lt;br&gt;
        &lt;br&gt;
         &lt;/div&gt;
          &lt;div id="Task"  style="display: none;"&gt; Outcome: &lt;br /&gt;
          &lt;textarea name="description" cols="70" rows="2"&gt;&lt;/textarea&gt;
              &lt;br /&gt;
          &lt;/div&gt;
          &lt;div id="Lead-in" style="display: none;"&gt;
        Link/Path:&lt;br&gt;
        &lt;br&gt;
         &lt;/div&gt;&lt;/td&gt;
      &lt;td width="120"&gt;&lt;input name="author" type="text" size="12" maxlength="25" /&gt;&lt;/td&gt;
    &lt;/tr&gt;
       &lt;tr&gt;
         &lt;td colspan="3"&gt;      &lt;textarea name="pre" id="Pre" cols="45" rows="5"&gt;&lt;/textarea&gt;
                         &lt;br /&gt;&lt;textarea name="whileact" id="whileact" cols="45" rows="5"&gt;&lt;/textarea&gt;
                         &lt;br /&gt;&lt;textarea name="postact" id="Post" cols="45" rows="5"&gt;&lt;/textarea&gt;
                         &lt;br /&gt;&lt;textarea name="outcome" id="Outcome" cols="45" rows="5"&gt;&lt;/textarea&gt;
                         &lt;br /&gt;&lt;input type="text" name="path" id="Path" /&gt;
                         &lt;br /&gt;&lt;input type="text" name="books" id="Books" /&gt;
                         &lt;br /&gt;&lt;input type="text" name="grouping" id="Grouping" /&gt;
                         &lt;br /&gt;&lt;input type="text" name="time" id="Time" /&gt;
                         &lt;/td&gt;
       &lt;/tr&gt;
      &lt;tr&gt;
         &lt;td colspan="3"&gt;&lt;input type="submit" name="submit" value="Comment" /&gt;&lt;/td&gt;
       &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>