title: Execute PHP using JavaScript onclick submit
body: <p>How do I execute PHP using a JavaScript onclick button?
  I can get the form to submit, but the PHP does not get executed. I assume it's because <code>if(isset($_POST['form']))</code></p>
  
  <p>Here is the PHP I want to execute:</p>
  
  <pre><code>if(isset($_POST['form']))
  {
      if(!isset($error))
      {
          $database-&gt;query('UPDATE table SET field = :value WHERE id = :id', array(':field' =&gt; $value, ':id' =&gt; $id));
      }
  }
  </code></pre>
  
  <p>Here is my button that is BEFORE my <code>&lt;form&gt;</code> tag:</p>
  
  <pre><code>&lt;div onclick="javascript: $(\'#form\').submit();"&gt;Update&lt;/div&gt;
  </code></pre>
  
  <p>And of course my <code>&lt;form&gt;</code> tag looks something like this:</p>
  
  <pre><code>&lt;form name="form" id="form" method="post" action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;"&gt;
    &lt;select name="value"&gt;
      &lt;option value="1"&gt;Value1&lt;/option&gt;
      &lt;option value="2"&gt;Value2&lt;/option&gt;
      &lt;option value="3"&gt;Value3&lt;/option&gt;
    &lt;/select&gt;
  &lt;/form&gt;
  </code></pre>