title: php works from action but not from onSubmit in html form
body: <p>I have an HTML form which gets some text data from the user. I want to insert that into my database and stay on the same form so that another row can be created in the database. I have the php working fine if I call it from the form using action='includes/addUser.php' but that then leaves the browser on the addUser.php page which doesnt display anything. I had thought I could use ajax to not change the display but the php does not seem to get called. If I change the name of the php file in the ajax call I do see an error.</p>
  
  <pre><code>&lt;div id="addUserFormDivID"&gt;
      &lt;!-- &lt;form id='addUserFormID' method='post' action='includes/addUser.php'&gt; --&gt;
      &lt;form id='addUserFormID' method='post' onSubmit='javascript:addUser()'&gt;
          Add User&lt;br /&gt;&lt;br /&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td align="right"&gt;Full name:&lt;/td&gt;
                  &lt;td align="left"&gt;&lt;input type="text" name="fullName" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td align="right"&gt;Nickname:&lt;/td&gt;
                  &lt;td align="left"&gt;&lt;input type="text" name="nickName" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td align="right"&gt;Email:&lt;/td&gt;
                  &lt;td align="left"&gt;&lt;input type="text" name="email" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td align="right"&gt;Phone:&lt;/td&gt;
                  &lt;td align="left"&gt;&lt;input type="text" name="phone" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td align="right"&gt;Postal Address:&lt;/td&gt;
                  &lt;td align="left"&gt;&lt;input type="text" name="address" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td align="right"&gt;Postcode:&lt;/td&gt;
                  &lt;td align="left"&gt;&lt;input type="text" name="postcode" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;            
          &lt;input type="submit" name="submitAddUser" value="Add User" style="float:right"&gt;  
      &lt;/form&gt;
  &lt;/div&gt;
  
  &lt;script type="text/javascript"&gt;
  
      function addUser() 
      {
          console.log("javascript addUser()");
  
          $.ajax
          ({
              type: "POST",
              url: "includes/addUser.php",
              //data: '1',
              success: function()
              {
                  alert("User added");
              }
          }); // Ajax Call            alert("hello");
      }
  </code></pre>
  
  <p>addUser.php:</p>
  
  <pre><code>&lt;?php
  
  include_once 'db_connect.php';
  include_once 'functions.php';
  //sec_session_start();
  
  debug_to_console("addUser.php");
  
  $fullName = $_POST[fullName];
  $nickName = $_POST[nickName];
  $email = $_POST[email];
  $phone = $_POST[phone];
  $address = $_POST[address];
  $postcode = $_POST[postcode];
  
  $stmt = mysqli_prepare($mysqli, "INSERT INTO Person (FullName, NickName, Email, Phone, PostalAddress, Postcode) VALUES (?, ?, ?, ?, ?, ?)");
  
  if ($stmt === false) 
  {
      trigger_error('Statement failed! ' . htmlspecialchars(mysqli_error($mysqli)), E_USER_ERROR);
  }
  
  $bind = mysqli_stmt_bind_param($stmt, "ssssss", $fullName, $nickName, $email, $phone, $address, $postcode );
  
  if ($bind === false) 
  {
      trigger_error('Bind param failed!', E_USER_ERROR);
  }
  
  $exec = mysqli_stmt_execute($stmt);
  
  if ($exec === false) 
  {
      trigger_error('Statement execute failed! ' . htmlspecialchars(mysqli_stmt_error($stmt)), E_USER_ERROR); 
  }
  
  //printf ("New Record has id %d.\n", mysqli_insert_id($mysqli));
  
  mysqli_stmt_close($stmt);
  
  echo "done addUser";
  </code></pre>
  
  <p>?></p>
  
  <p>with the action='includes/addUser.php' line not commented out (and the onSubmit commented out) then it works as I want up to displaying a blank page</p>
  
  <p>With the onSubmit line active instead, the javascript addUser function is called ("javascript addUser()" is output to the console and the alert is shown with "User added") but nothing in the addUser.php file seems to be run. If I include_once a nonexistent file at the start of addUser.php, I dont see an error.</p>