phpsane Posted October 15, 2018 Share Posted October 15, 2018 (edited) Folks, Look at this login.php. It works if I remove the following: if (!mysqli_stmt_fetch($stmt_1)) { echo "Incorrect log-in details1!<br>"; mysqli_stmt_close($stmt_1); exit(); } And remove the following: if (!mysqli_stmt_fetch($stmt_2)) { echo "Incorrect log-in details2!<br>"; mysqli_stmt_close($stmt_2); exit(); } Else, I get following error, even if login inputs are correct: Incorrect log-in details1! Why is that ? Full code: (removed since it's in the next post) Edited October 15, 2018 by requinix Quote Link to comment Share on other sites More sharing options...
phpsane Posted October 15, 2018 Author Share Posted October 15, 2018 Sorry. Here, full code again: <?php //Required PHP Files. include 'config.php'; //Required on all webpages of the site. //Check if User is already logged-in or not. Get the login_check() FUNCTION to check. if (login_check() === TRUE) { //Redirect User to Log-in Page immediately. //header("refresh:0; url=home.php"); header("location:home.php?user=$user"); exit(); } if (isset($_POST["login_username_or_email_or_domain"]) && isset($_POST["login_password"])) { $login_username_or_email_or_domain = trim($_POST["login_username_or_email_or_domain"]); $login_password = $_POST["login_password"]; //Check if User inputted Username/Email exist in db. Registered or not. //Select Username or Email to check against Mysql DB if they are already registered or not. if(strpos("login_username_or_email_or_domain", "@")) { $querying_column = "primary_website_email"; } elseif(strpos("login_username_or_email_or_domain", ".")) { $querying_column = "primary_website_domain"; } else { $querying_column = "username"; } //Make sure the users table has atleast these 3 columns: username,primary_website_domain and primary_website_email due to the $querying_column variable which could hold any of these 3 values. $query_1 = "SELECT id,account_activation_status,id_video_verification_status,sponsor_username,username,password,primary_website_domain,primary_website_email,first_name,middle_name,surname,gender,age_range,country FROM users WHERE $querying_column = ?"; $stmt_1 = mysqli_prepare($conn, $query_1); mysqli_stmt_bind_param($stmt_1, 's', $login_username_or_email_or_domain); mysqli_stmt_execute($stmt_1); $result_1 = mysqli_stmt_bind_result($stmt_1,$db_id,$db_account_activation_status,$db_id_video_verification_status,$db_sponsor_username,$db_username,$db_password,$db_primary_website_domain,$db_primary_website_email,$db_first_name,$db_middle_name,$db_surname,$db_gender,$db_age_range,$db_country); mysqli_stmt_fetch($stmt_1); if (!mysqli_stmt_fetch($stmt_1)) { echo "Incorrect log-in details1!<br>"; mysqli_stmt_close($stmt_1); exit(); } mysqli_stmt_close($stmt_1); //Free Result_1 Set mysqli_stmt_free_result($stmt_1); $query_2 = "SELECT blog,personal_email,personal_mobile,home_zip,home_town,home_borough,home_city,home_county,home_region,home_state,home_country,business_name,business_email,business_phone,business_zip,business_town,business_borough,business_city,business_county,business_region,business_state,business_country FROM contact_details WHERE id = ?"; $stmt_2 = mysqli_prepare($conn, $query_2); mysqli_stmt_bind_param($stmt_2, 's', $db_id); mysqli_stmt_execute($stmt_2); $result_2 = mysqli_stmt_bind_result($stmt_2,$db_blog,$db_personal_email,$db_personal_mobile,$db_home_zip,$db_home_town,$db_home_borough,$db_home_city,$db_home_county,$db_home_region,$db_home_state,$db_home_country,$db_business_name,$db_business_email,$db_business_phone,$db_business_zip,$db_business_town,$db_business_borough,$db_business_city,$db_business_county,$db_business_region,$db_business_state,$db_business_country); mysqli_stmt_fetch($stmt_2); if (!mysqli_stmt_fetch($stmt_2)) { echo "Incorrect log-in details2!<br>"; mysqli_stmt_close($stmt_2); exit(); } mysqli_stmt_close($stmt_2); //Free Result_2 Set mysqli_stmt_free_result($stmt_2); if (!password_verify($login_password, $db_password)) { echo "Incorrect log-in details3<br>"; exit(); } else { $user = $db_username; $_SESSION["user"] = $user; $_SESSION["id"] = $db_id; $_SESSION["account_activation_status"] = $db_account_activation_status; $_SESSION["id_video_verification_status"] = $db_id_video_verification_status; $_SESSION["id_video_verification_url"] = $db_id_video_verification_url; $_SESSION["sponsor_username"] = $db_sponsor_username; $_SESSION["recruits_number"] = $db_recruits_number; $_SESSION["primary_website_domain"] = $db_primary_website_domain; $_SESSION["primary_website_email"] = $db_primary_website_email; $_SESSION["username"] = $db_username; $_SESSION["first_name"] = $db_first_name; $_SESSION["middle_name"] = $db_middle_name; $_SESSION["surname"] = $db_surname; $_SESSION["gender"] = $db_gender; $_SESSION["date_of_birth"] = $db_date_of_birth; $_SESSION["age_range"] = $db_age_range; $_SESSION["religion"] = $db_religion; $_SESSION["education"] = $db_education; $_SESSION["profession"] = $db_profession; $_SESSION["marital_status"] = $db_marital_status; $_SESSION["working_status"] = $db_working_status; $_SESSION["home_town"] = $db_home_town; $_SESSION["home_borough"] = $db_home_borough; $_SESSION["home_city"] = $db_home_city; $_SESSION["home_county"] = $db_home_county; $_SESSION["home_region"] = $db_home_region; $_SESSION["home_state"] = $db_home_state; $_SESSION["home_country"] = $db_home_country; include 'sessions.php'; header("location:home.php?user=$user"); } } ?> <!DOCTYPE html> <html> <head> <title><?php $site_name ?> Member Login Page</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <form name = "login_form" method = "post" action="" enctype = "multipart/form-data"> <h3><?php echo "$site_name";?> Member Login Form</h3> <fieldset> <label for="login_name">Username/Email:</label> <input type="text" name="login_username_or_email_or_domain" id="login_name" required [A-Za-z0-9] autocorrect=off value=""><br> <label for="login_pass">Password:</label> <input type="password" name="login_password" id="login_pass" required [A-Za-z0-9] autocorrect=off value=""> </fieldset> <div class="SubmitsAndHiddens"> <label for="login_remember">Remember Log-in Details:</label> <input type="checkbox" name="login_remember" id="login_remember" /> <br> <p align="left"><input type="submit" class="btn btn-default" name="submit" value="Log-in!"></p> <br> <a href="login_password_reset.php">Forgot your password ? Reset it here!</a> <br> <a href="register.php">Don't yet have an account ? Register here!</a> </div> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
phpsane Posted October 15, 2018 Author Share Posted October 15, 2018 Guys, Looking at my login.php, on my previous post, can someone be kind enough to add the cookie code so I can learn from your way of coding ? Your style. Thanks! Quote Link to comment Share on other sites More sharing options...
gizmola Posted October 15, 2018 Share Posted October 15, 2018 58 minutes ago, phpsane said: Guys, Looking at my login.php, on my previous post, can someone be kind enough to add the cookie code so I can learn from your way of coding ? Your style. What do you want to set a cookie for and why? Quote Link to comment Share on other sites More sharing options...
ginerjm Posted October 15, 2018 Share Posted October 15, 2018 So - phpsane is now 'site-developer' on the other forum. What a misnomer! Quote Link to comment Share on other sites More sharing options...
Barand Posted October 15, 2018 Share Posted October 15, 2018 As for your original question (had you forgotten about that one?) - You have a query which returns one record You fetch that record You then try to fetch another and wonder why it fails 1 Quote Link to comment Share on other sites More sharing options...
benanamen Posted October 16, 2018 Share Posted October 16, 2018 5 hours ago, ginerjm said: So - phpsane is now 'site-developer' on the other forum. What a misnomer! Depending on what forum you are on and how many times he was banned from it or how many duplicate accounts he signed up will determine which of the at least 10 usernames the OP goes by. It would make a heck of a switch statement if you were to program it out. Quote Link to comment Share on other sites More sharing options...
phpsane Posted October 24, 2018 Author Share Posted October 24, 2018 (edited) On 10/16/2018 at 1:11 AM, gizmola said: What do you want to set a cookie for and why? So, you don't have to type your username & password while cookie sitll exsts. Edited October 24, 2018 by phpsane Quote Link to comment Share on other sites More sharing options...
phpsane Posted October 24, 2018 Author Share Posted October 24, 2018 On 10/16/2018 at 1:28 AM, Barand said: As for your original question (had you forgotten about that one?) - You have a query which returns one record You fetch that record You then try to fetch another and wonder why it fails Sorry! don't understand your hint.Both record do get fetched when I remove the 2 lines mentioned in my original post. Why they prevent the fetching of the 1st record ? Quote Link to comment Share on other sites More sharing options...
Barand Posted October 25, 2018 Share Posted October 25, 2018 On 10/15/2018 at 7:09 PM, phpsane said: mysqli_stmt_fetch($stmt_2); if (!mysqli_stmt_fetch($stmt_2)) First line above fetches first record and completely ignores it. Second line fetches next record, if there is one, or gives error message if there isn't 1 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.