I am having a small problem with my jQuery function, and below is the code:
function registerUser()
{
var formData = $('#registerForm').serialize();
var dataPost = $.post('classes/login.php', {type:'register', data: formData} ,function (data)
{
console.log(data);
});
};
Then my login.php file looks like:
$type = $_POST['type'];
$email = $_POST['data']['0'];
$password = $_POST['data']['1'];
function register_user($email, $password)
{
global $db;
//lets add some code to register user
$stmt = $db->prepare("INSERT INTO user (email, password, role, banned) VALUES (:email, :password, 'level1', 'N')");
$stmt->execute(array(':email'=> $email, ':password'=> $password));
$rowCount = $stmt->rowCount();
if($rowCount > 0)
{
// Success
// set session data and etc.
return "success";
}
else
{
// Failed
return "Error, please try again!";
}
}
$result = register_user($email, $password);
When I executed it I did not get any errors or anything but a simple blank line that does not show any data and the data does not get inserted into the database?