index.php
<form method="post">
<input id="name" type="text" name="name" class="form-control" placeholder="Name">
<input id="button" type="button" value="Load">
</form>
$('#button').click(function(){
var name = $('#name').val();
$.ajax({
url: 'User.php',
method:"POST",
data: 'name='+name,
});
});
User.php
<?php
include 'Database.php';
include_once 'Session.php';
class User
{
private $db;
public function __construct()
{
$this->db = new Database();
}
public function userRegistration()
{
$name = $_POST['name'];
$sql = "INSERT INTO users(name) VALUES(:name)";
$query = $this->db->pdo->prepare($sql);
$query->bindValue(':name', $name);
$result = $query->execute();
return $result;
}
}
if(isset($_POST['name'])) {
$register = new User();
$result = $register->userRegistration();
echo $result;
}