ossieboy Posted February 8, 2020 Share Posted February 8, 2020 Hi Can anyone help with this problem it seems very simple, I am not an experienced PHP coder but keen to progress. I am trying to create a User Registration project but have a problem. every time I try to login using mysqli_fetch_assoc it drops through to my error Invalid Email /Password it seems that the mysqli code is not working correctly but I do not understand this function enough can anyone help. I have attached the coding if this helps. This is the function function Login_Attempt($Email,$Password){ $Query="SELECT * FROM admin_panel WHERE email='$Email'"; $Execute=mysqli_query($Connection,$Query); if($admin=mysqli_fetch_assoc($Execute)){ if(Password_Check($Password,$admin["password"])){ echo $Email; return $admin ; } }else{ return null; } } This is the code I am using Login.php <?php require_once("Include/Session.php"); ?> <?php require_once("Include/Styles.css"); ?> <?php require_once("Include/Functions.php"); ?> <?php require_once("Include/DB.php"); ?> <?php if(isset($_POST["Submit"])){ $Email=mysqli_real_escape_string($Connection,$_POST["Email"]); $Password=mysqli_real_escape_string($Connection,$_POST["Password"]); if(empty($Email)||empty($Password)){ $_SESSION["message"]="All Fields must be filled out"; Redirect_To("Login.php"); }else{ if(ConfirmingAccountActiveStatus()){ $Found_Account=Login_Attempt($Email,$Password); if($Found_Account){ $_SESSION["User_Id"]=$Found_Account['id']; $_SESSION["User_Name"]=$Found_Account['username']; $_SESSION["User_Email"]=$Found_Account['email']; if(isset($_POST["Remember"])){ $ExpireTime=time()+86400; setcookie("SettingEmail",$Email,$ExpireTime); setcookie("SettingName",$Username,$ExpireTime); } Redirect_To("Welcome.php"); }else{ $_SESSION["message"]="Invalid Email / Password"; Redirect_To("Login.php"); } }else{ $_SESSION["message"]="Account Confirmation Required"; Redirect_To("Login.php"); } } } ?> <?php ?> <!DOCTYPE> <html> <head> <title>Login</title> </head> <body> <div> <?php echo Message(); ?> <?php echo SuccessMessage(); ?></div> <div id="centerpage"> <br><a href="User_Registration.php"><span class="FieldInfo">Don't Have an account? Creat One !</span></a><br> <form action="Login.php" method="post"> <fieldset> <span class="FieldInfo">Email:</span><br><input type="email" Name="Email" value=""><br> <span class="FieldInfo">Password:</span><br><input type="password" Name="Password" value=""><br> <input type="checkbox" Name="Remember" ><span class="FieldInfo"> Remember me<span class="FieldInfo"><br> <br><a href="Recover_Account.php"><span class="FieldInfo">Forgot Password</span></a> <br><input type="Submit" Name="Submit" value="Login"><br> </fieldset> </form> </div> </body> </html> Hope this Helps Ossieboy Quote Link to comment Share on other sites More sharing options...
gw1500se Posted February 8, 2020 Share Posted February 8, 2020 You are not passing $Connection to the function so it is undefined. If you had errors turned on you would have seen that. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.