I have written a login script as below. Can anyone help me to get the current user id within below script? (auto increment id in mysql table). I'm unable to figure out any concept to work within below script, I also need the $_SESSION['user'] = $type; which is currently assigned and working fine, beside this I just want to add the auto increment id within a session variable without any authentication. I appreciate your help :)
login.php
if(isset($_POST['email'], $_POST['password'], $_POST['type'])){
$email = $_POST['email'];
$password = $_POST['password'];
$type = $_POST['type'];
if(auth_user($email, $password, $type)){
$_SESSION['user'] = $type;
header('location: index.php');
} else {
echo '<span class="text-info success">Invalid email or password!</span>';
}
}
html fields
<input type="text" class="form-control" placeholder="Enter Email" name="email" />
<input type="password" class="form-control" placeholder="Enter Password" name="password" /><br />
<input type="hidden" id="type" value="user" name="type" /><br />
<button type="submit" class="btn btn-default" value="Login">Login </button>
functions.php
//auth user****
function auth_user($email, $password, $type){
mysql_select_db('drive') or die(mysql_error());
$sql = "SELECT `user`.`password` AS `pass` FROM `user` WHERE `user`.`email` = '$email' and `user`.`type` = '$type'";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
if($row['pass'] == $password){
return true;
} else {
return false;
}
}