I am using this code to submit my form
$('.login-form input').keypress(function (e) {
if (e.which == 13) {
if ($('.login-form').validate().form()) {
//$( "#login-form input" ).submit();
// window.location.href = "check.php";
$.post("check.php", $("#login-form input").serialize(), function(data) {
window.location.href = "check.php";
});
}
return false;
}
});
I am not able to get values in check.php. kindly help me. I know its a basic thing but I am not able to do this. Thanks in advance
Here is my php code
<?php
session_start();
include_once("Includes/db_connection.php");
include_once("participant/welcome.php");
include_once("admin/admin_login.php");
include_once("staff/staff_login.php");
include_once("lecturer/lecturer_login.php");
include("Includes/location.php");
//include("Includes/lecturer_data_dropdown.php");
$username=$_POST["username"];
$password=$_POST["password"];
echo $username;
if($_POST["user_type"]=="participant")
{
participant($password);
}
elseif($_POST["user_type"]=="admin")
{
admin($username, $password);
}
elseif($_POST["user_type"]=="staff")
{
staff($username, $password);
}
elseif($_POST["user_type"]=="lecturer")
{
lecturer($username, $password);
}
?>
Here i just need usertype, username and password to make login decisions
I notice you're referencing $('.login-form')
in one section of your code and $('#login-form')
in another. If your form is in fact using a class instead of an ID, the .serialize() method will return an empty array. Update it to $('.login-form input')
(note the period instead of the hash).
More info on jQuery selectors: https://api.jquery.com/category/selectors/
Try this i've tried and its working just fine:
var var_username=$("Id of input box for username").val();
var var_password= $("Id of input box for password").val();
$.post(URL,
{
username: var_username,
password: var_password
},
success:function(data)
{
//your message here..
}
);