Jump to content

Why If Not Statement Fetch Condition Fails ?


phpsane

Recommended Posts

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)

Link to comment
Share on other sites

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>
	

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...
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 ?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.