var username = $('#username').val();
var dataString = 'username=' + username;
$.ajax({
type: "POST",
url: "signinout.php",
data: dataString,
success: function() {
$('.user').html('<span>Welcome <span id="loggedUser">' + username + '</span>!</span> <a id="signOut" onclick="window.location.reload()">SIGN OUT</a>');
}
});
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.
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.
$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));