title: What is causing PHP Notice: Undefined index:?
body: <p>I have a user registration form in my jQuery mobile app but when I submit the form via an $.ajax call it inserts only a blank row and the error_log says:</p>
  
  <pre><code>[01-Dec-2013 13:27:13] PHP Notice:  Undefined index:  fname in /home2/hedonsof/public_html/tcob/php/register.php on line 10
  [01-Dec-2013 13:27:13] PHP Notice:  Undefined index:  lname in /home2/hedonsof/public_html/tcob/php/register.php on line 11
  [01-Dec-2013 13:27:13] PHP Notice:  Undefined index:  username in /home2/hedonsof/public_html/tcob/php/register.php on line 12
  [01-Dec-2013 13:27:13] PHP Notice:  Undefined index:  password in /home2/hedonsof/public_html/tcob/php/register.php on line 13
  [01-Dec-2013 13:27:13] PHP Notice:  Undefined index:  email in /home2/hedonsof/public_html/tcob/php/register.php on line 14
  </code></pre>
  
  <p>My index:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;jQuery Mobile Web App&lt;/title&gt;
  &lt;link href="lib/BlackBerry-JQM-all-1.0.0.css" rel="stylesheet" type="text/css"/&gt;
  &lt;link href="style/main.css" rel="stylesheet" type="text/css"/&gt;
  &lt;script src="lib/BlackBerry-JQM-all-1.0.0.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="ui/jquery.ui.map.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="ui/jquery.ui.map.services.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="ui/jquery.ui.map.extensions.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="app.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src=http://maps.googleapis.com/maps/api/js?sensor=false type="text/javascript"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div data-role="page" id="landing"&gt;
    &lt;div data-role="header"&gt; &lt;/div&gt;
    &lt;div data-role="content"&gt;
      &lt;div id="map_
      canvas" style="height:600px"&gt; &lt;/div&gt;
      &lt;div id="info"&gt; &lt;/div&gt;
    &lt;/div&gt;
    &lt;div data-role="footer"&gt;
      &lt;div data-role="actionbar"&gt; &lt;a id="help" data-role="tab"&gt; &lt;img src="img/ic_help.png"/&gt;
        &lt;p&gt;Help&lt;/p&gt;
        &lt;/a&gt; &lt;a id="chat" data-role="tab"&gt; &lt;img src="img/ic_textmessage.png"/&gt;
        &lt;p&gt;Chat&lt;/p&gt;
        &lt;/a&gt; &lt;a id="add" data-role="tab" href="#add"&gt; &lt;img src="img/ic_add.png"/&gt;
        &lt;p&gt;Add &lt;/p&gt;
        &lt;/a&gt; &lt;a id="settings" data-role="tab" href="#register"&gt; &lt;img src="img/Core_applicationmenu_icon_settings.png" alt="" /&gt;
        &lt;p&gt;Settings&lt;/p&gt;
        &lt;/a&gt; &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div data-role="page" id="register"&gt;
    &lt;div data-role="header"&gt; &lt;/div&gt;
    &lt;div data-role="content"&gt;
      &lt;div class="BB10Container"&gt;
        &lt;form id="adduser"&gt;
  &lt;label for="fname"&gt;First Name&lt;/label&gt;
          &lt;input type="text" name="fname" id="fname" placeholder="John"/&gt;
          &lt;label for="lname"&gt;Last Name&lt;/label&gt;
          &lt;input type="text" name="lname" id="lname" placeholder="Doe"/&gt;
          &lt;label for="username"&gt;Username&lt;/label&gt;
          &lt;input type="text" name="username" id="username" placeholder="Username"/&gt;
          &lt;label for="basic"&gt;Password&lt;/label&gt;
          &lt;input type="password" name="password" id="password" placeholder="Password"/&gt;
          &lt;label for="verpass"&gt;Repeat Password&lt;/label&gt;
          &lt;input type="password" name="verpass" id="verpass" placeholder="Password"/&gt;
          &lt;label for="regemail"&gt;Email&lt;/label&gt;
          &lt;input type="email" name="email" id="email" placeholder="your@email.com"/&gt;
          &lt;input type="submit" data-role="button" data-inline="true" data-icon="check" value="Submit" id="regsubmit"&gt;
  &lt;/form&gt;
  
      &lt;/div&gt;
      &lt;div id="info"&gt; &lt;/div&gt;
    &lt;/div&gt;
    &lt;div data-role="footer"&gt;
      &lt;div data-role="actionbar"&gt; &lt;a id="help" data-role="tab"&gt; &lt;img src="img/ic_help.png"/&gt;
        &lt;p&gt;Help&lt;/p&gt;
        &lt;/a&gt; &lt;a id="chat" data-role="tab"&gt; &lt;img src="img/ic_textmessage.png"/&gt;
        &lt;p&gt;Chat&lt;/p&gt;
        &lt;/a&gt; &lt;a id="add" data-role="tab" href="#add"&gt; &lt;img src="img/ic_add.png"/&gt;
        &lt;p&gt;Add &lt;/p&gt;
        &lt;/a&gt; &lt;a id="settings" data-role="tab" href="#settings"&gt; &lt;img src="img/Core_applicationmenu_icon_settings.png" alt="" /&gt;
        &lt;p&gt;Settings&lt;/p&gt;
        &lt;/a&gt; &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;script type="text/javascript"&gt;
  
   $(document).ready(function() {
      $("#regsubmit").click(function(){
  
          var formData = $("#adduser").serialize();
   alert(formData);   
          $.ajax({
              type: "POST",
              url: "register.php",
              cache: false,
              data: fname: fname,
                    lname: lname,
                    username: username,
                    password: password,
                    email: email,
              success: onSuccess
          });
  
          return false;
      }); 
   });
  
   function onSuccess(data, status)
  {
      alert('Success');
  }
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>My PHP</p>
  
  <pre><code>&lt;?php
  require('connect.php');
  ini_set('display_errors', 'On');
  error_reporting(E_ALL);
  try{
  $db = mysql_connect($host, $dbusername, $password ) or die(mysql_error());
      mysql_select_db($db_name) or die(mysql_error());
  
      // Note: You need to verify the data coming in isn't harmful, this SQL pretty much puts anything into the database so make sure to change this!
          $fname = $_POST['fname'];
          $lname =$_POST['lname'];
          $username = $_POST['username'];
          $password = $_POST['password'];
          $email = $_POST['email'];
  
          mysql_query("INSERT INTO members (fname, lname, username, password,email) VALUES ('$fname', '$lname','$username','$password','$email')");
          mysql_close($db);
          echo "SUCCESS";
      }
      catch(Exception $e)
      {
          echo $e-&gt;getMessage();
          // Note: Log the error or something
      }
  ?&gt;
  </code></pre>