I've just set up a local MAMP enviroment and I'm trying to insert just a name in to a database table as a test. I'm not getting any errors in the console or PHP log but for the life of me I can't get it to insert the data in to the database.
HTML:
<form action="" method="GET" name="nameSubmit">
   <input type="input" name="userName"  class="user-name">
   <input type="submit" value="Submit" class="name-submit">
</form>
JS:
var userSubmitButton = $('.name-submit'),
    userNameInput = $('.user-name'),
    userName;
userSubmitButton.click(function(e){
e.preventDefault();
userName = userNameInput.val();
console.log(userName);
$.ajax({
    url: "nameSubmit.php",
    type : "GET",
    dataType : "json",
    data : {type : "nameSubmit", name : userName},
    success : function(response){
        alert(JSON.stringify(response));
    },
    error : function(err){
        alert(JSON.stringify(err));
    }
 });
});
PHP:
<?php
$mysqli = mysqli_connect("localhost", "root", "root", "test_name");
if (isset($_GET['type'])){
if($_GET['type'] == "nameSubmit"){
    $name = $_GET['name'];
    $stmt = $mysqli->prepare("INSERT INTO names (name) VALUES ('$name')");
    echo "$name";
}
}
?>
The response says its completed all tasks and returns $name
 
     
    