ERROR : Undefined array key 'u_email'
and it says the same about 'u_pass'.
The names are correct. In database they're saved with the same name as well.
Here's my code:
function login(){
if(isset($_POST['login'])){
$email=$_POST['u_email'];
$password=$_POST['u_pass'];
include 'config/connections.php';
if($email!="" && $password!=""){
$q="SELECT* FROM users WHERE u_email= '$email' AND u_pass='$password'";
$q_run=mysqli_query($con,$q);
$data=mysqli_fetch_array($q_run);
if($data['u_email']==$email && $data['u_pass']==$password){
$_SESSION['id']=$data['u_id'];
$_SESSION['name']=$data['u_name'];
$_SESSION['email']=$data['u_email'];
$_SESSION['password']=$data['u_pass'];
?>
<div class="alert alert-success mt-3">Logging in. Please wait...</div>
<script>
setTimeout(function(){
window.location='home.php';
}, 2000);
</script>
<?php
}
else{
?>
<div class="alert alert-danger mt-3">Invalid Email or Password</div>
<?php
}
}else{
?>
<div class="alert alert-danger mt-3">Please Enter Email and Password</div>
<?php
}
}
}
source https://stackoverflow.com/questions/70264643/php-undefined-array-key-error-in-login-function
No comments:
Post a Comment