title: PHP ajax not updating database
body: <p>I'm currently trying to update my database with <code>PHP</code> and <code>AJAX</code> but this doesn't seem to work and i can't currently locate where the error is from</p>
  
  <p>Here are my codes</p>
  
  <p><strong>php</strong></p>
  
  <pre><code>&lt;?php 
    $userid = $_GET['userid'];
    $_SESSION['userid'] = $userid;
    $sql = $db-&gt;prepare("SELECT * FROM users WHERE userid = ?");
    $sql-&gt;bindParam(1, $userid);
    $result = $sql-&gt;execute();
    while ($row = $result-&gt;fetchArray(SQLITE3_ASSOC)) 
    {
        $fname = $row['fname'];
        $lname = $row['lname'];
        $cname = $row['cname'];
        $crcnum = $row['crcnum'];
        $uemail = $row['uemail'];
        $uname = $row['uname'];
        $regas = $row['regas'];
        $caddress = $row['caddress'];
        $uaddress = $row['uaddress'];
        $package = $row['package'];
        $regdate = $row['regdate'];
        $expdate = $row['expdate'];
        $profimages = $row['profimages'];
        $coverimage = $row['coverimage'];
        ?&gt;
        &lt;style type="text/css"&gt;
          .loginDanger {
              width: 100%;
          }
        &lt;/style&gt;
        &lt;div class="upgrForm"&gt;
              &lt;div class="logresult"&gt;&lt;/div&gt;
              &lt;form action="upgformexec.php" method="post" enctype="multipart/form-data"&gt;
              &lt;?php 
  
              echo "&lt;p class='pcLabel'&gt;Current Package&lt;/p&gt;";
  
              if ($package == "Gold")
              {
                  echo "&lt;p class='goldpacks'&gt;$package&lt;/p&gt;
                  &lt;p class='pcLabel'&gt;This user is already on the highest package!.&lt;/p&gt;";
              }
              if ($package == "Silver")
              {
                  echo "&lt;p class='silvpacks'&gt;$package&lt;/p&gt;
                  &lt;p class='pcLabel'&gt;Ugrade Pack To&lt;/p&gt;
              &lt;select name='newPack' id='newPack'&gt;
                  &lt;option&gt;--Select--&lt;/option&gt;
                  &lt;option&gt;Gold&lt;/option&gt;
              &lt;/select&gt;
              &lt;input type='submit' name='upgrdSub' id='upgrdSub' value='Execute Upgrade'&gt;";
              }
              if ($package == "Bronze")
              {
                  echo "&lt;p class='bronzpacks'&gt;$package&lt;/p&gt;
                  &lt;p class='pcLabel'&gt;Ugrade Pack To&lt;/p&gt;
              &lt;select name='newPack' id='newPack'&gt;
                  &lt;option&gt;--Select--&lt;/option&gt;
                  &lt;option&gt;Silver&lt;/option&gt;
                  &lt;option&gt;Gold&lt;/option&gt;
              &lt;/select&gt;
              &lt;input type='submit' name='upgrdSub' id='upgrdSub' value='Execute Upgrade'&gt;";
              }
              if ($package == "Free Membership")
              {
                  echo "&lt;p class='freepacks'&gt;$package&lt;/p&gt;
                  &lt;p class='pcLabel'&gt;Ugrade Pack To&lt;/p&gt;
              &lt;select name='newPack' id='newPack'&gt;
                  &lt;option&gt;--Select--&lt;/option&gt;
                  &lt;option&gt;Bronze&lt;/option&gt;
                  &lt;option&gt;Silver&lt;/option&gt;
                  &lt;option&gt;Gold&lt;/option&gt;
              &lt;/select&gt;
              &lt;input type='submit' name='upgrdSub' id='upgrdSub' value='Execute Upgrade'&gt;";
              }
              ?&gt;       
  &lt;/form&gt;
  </code></pre>
  
  <p>Below is code to execute the form</p>
  
  <pre><code>&lt;?php 
  session_start();
  require_once ("db.php");
  $db = new MyDb();
  
  $userid = $_SESSION['userid'];
  
  if (isset($_POST['upgrdSub']))
  {
      $newpack = strip_tags(@$_POST['newPack']);
  
      $sql = $db-&gt;prepare("UPDATE users SET package = ? WHERE userid = ?");
      $sql-&gt;bindParam(1, $newpack, SQLITE3_TEXT);
      $sql-&gt;bindParam(2, $userid);
      $result = $sql-&gt;execute();
  
      if ($result) 
      {
          echo "true";
      }
      else
      {
          echo "false";
      }
  }
  ?&gt;
  </code></pre>
  
  <p>Below is the ajax request</p>
  
  <pre><code>$(document).ready(function() {
      $("#upgrdSub").click(function() {
        //e.preventDefault();
        newpack=$("#newPack").val();
        $.ajax({
          type: "POST",
          url: "upgformexec.php",
          data: "newPack="+newpack,
          success: function(html){
            if (html == 'true')
            {
                $(".logresult").html('&lt;div class="loginSuccess"&gt;&lt;i class="fa fa-tick"&gt;&lt;/i&gt;  Upgrade Successful.&lt;/div&gt;');
            }
            else
            {
                $(".logresult").html('&lt;div class="loginDanger"&gt;&lt;i class="fa fa-exclamation-triangle"&gt;&lt;/i&gt;  Please select a package to upgrade to!.&lt;/div&gt;');
            }
            if (html == 'false')
            {
                $(".logresult").html('&lt;div class="loginDanger"&gt;&lt;i class="fa fa-exclamation-triangle"&gt;&lt;/i&gt; There was an error upgrading this account!. Please try again later.&lt;/div&gt;');
            }
          },
          beforeSend:function()
          {
            $(".logresult").html("&lt;img src='images/ring.gif'&gt;");
          }
        });
        return false;
      }); 
  });
  </code></pre>
  
  <p>For some reason, the form submits without the ajax request but when i had the ajax, i get the "Please select package to upgrade to" feedback. How can this be resolved? Thanks</p>