title: how do i pass datastring parameter for jquery's .ajax() function properly?
body: <pre><code>var username = $('#username').val();
  
  var dataString = 'username=' + username;
  
      $.ajax({
          type: "POST",
          url: "signinout.php",
          data: dataString,
          success: function() {
              $('.user').html('&lt;span&gt;Welcome &lt;span id="loggedUser"&gt;' + username + '&lt;/span&gt;!&lt;/span&gt; &lt;a id="signOut" onclick="window.location.reload()"&gt;SIGN OUT&lt;/a&gt;');
          }
      });
  </code></pre>
  
  <p>using the above code, my username variable is not being passed on correctly, I'm assuming something is wrong with the way I coding the datastring parameter but I'm not sure how to do it correctly.</p>
  
  <p>Below is the php code that I am using in signinout.php to insert the username into the database, the username field is not being entered with each new entry into the database.</p>
  
  <pre><code>$username = protect($_POST['username']);
  $time = time();
  
  $sql = "INSERT INTO users
      (username, join_date)
          VALUES
      ('$username', '$time')";
  $result = mysqli_query($cn, $sql) or
      die(mysqli_error($cn));
  </code></pre>