I got here a working code that returns the corresponding user_id of the user when he logs in. But then, I need to use the $.get or $.post of jquery so that there will be no page refresh. I read posts about using $.get and $.post, but I doesn't seem to understand them.
Here is my working code. Please help me apply $.get or $.post to this. thanks!
<?php
$login = array
(
0=>array
( 'username'=>'Art',
'password'=>'p@ssw0rd',
'user_id'=>'1'
),
1=>array
( 'username'=>'Berto',
'password'=>'1234',
'user_id'=>'2'
),
2=>array
( 'username'=>'Carrie',
'password'=>'5678',
'user_id'=>'3'
),
3=>array
( 'username'=>'Dino',
'password'=>'qwer',
'user_id'=>'4'
),
4=>array
( 'username'=>'Ely',
'password'=>'asdf',
'user_id'=>'5'
)
);
if (isset($_POST['submit']))
{
$found_user = false;
$uname = $_POST['user'];
$pass = $_POST['password'];
foreach ($login as $sub_array) {
if ($uname == $sub_array['username'] && $pass == $sub_array['password']) {
$found_user = true;
$message = $sub_array['user_id'];
break;
}
}
if ($found_user) {
$message = ( $sub_array['user_id'] );
echo "<script type='text/javascript'>
alert('Your user ID is : $message');
</script>";
} else {
echo "<script type='text/javascript'>
alert('Invalid username/password.');
</script>";
}
}
?>
<body>
<form action="" method="post">
<label for="name"><span class="nameLabel">Username: </span></label>
<span class="nameLabel">
<input name="user" type="text" class="name" id="user" />
</span>
<label for="pass" class="passwordLabel">Password: </label>
<input name="password" type="password" class="password" id="password" />
<input name="submit" type="submit" class="logIn" id="login" value="Log In"/>
</form>
</body>