Webmaster Sun Login
Not a member yet? Sign up

Error: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in ......

  • HOME
  • FORUMS
  • BLOGS
  • MARKETPLACE
  • ADVERTISING
  • SPECIAL OFFERS
  • WEB HOSTING
  • QUICK MENU
  • REGISTER HERE - Join us for FREE
Results 1 to 8 of 8
    Stick this thread
  1. #1
    Join Date
    Jun 2017
    Posts
    6
    Thumbs Up/Down
    Received: 0/0
    Given: 1/0
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Error: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in ......

    Fellow Php Programmers,

    This is a script that takes over when a user clicks a link emailed to him. The link that verifies the user's email and opens his membership account by switching from "pending status = 0" to "pending status = 1" in mysql db.

    I am shown this by my script. And, I want to know why I get these errors:

    string(23) "[email protected]" string(40) "472b07b9fcf2c2451e8781e944bf5f77cd8457c8" object(mysqli_stmt)#2 (10) { ["affected_rows"]=> int(0) ["insert_id"]=> int(0) ["num_rows"]=> int(0) ["param_count"]=> int(2) ["field_count"]=> int(2) ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["sqlstate"]=> string(5) "00000" ["id"]=> int(1) } NULL
    Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in /home/EDITED (User)/public_html/e-id/activate_account.php on line 27
    bool(false) int(1) string(8) "EDITED (User)"
    Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in /home/EDITED (User)/public_html/e-id/activate_account.php on line 29

    Note the bool(false) in the first warning. Regarding line 27.
    Line 27:

    Code:
    $stmt_two (line 26) looks like this:
    mysqli_stmt_bind_param($stmt_two, 'is', $userActivationState, $username);
    Code:
    <?php
    02
    include 'config.php';
    03
    if (!isset($_GET["email"], $_GET["account_activation_code"]) === true){
    04
        $_SESSION['error'] = "Invalid Email Address! Invalid Account Activation Link! This email is not registered! Try registering an account if you do not already have one! <a href=\"register.php\">Register here!</a>";
    05
        exit();
    06
    }
    07
    else
    08
    {  
    09
        $email = htmlspecialchars($_GET['email']); 
    10
        $account_activation_code = htmlspecialchars($_GET['account_activation_code']); 
    11
        $stmt_one = mysqli_prepare($conn, "SELECT usernames, accounts_activations FROM users WHERE emails = ? AND accounts_activations_codes = ?");
    12
        mysqli_stmt_bind_param($stmt_one, 'si', $email,  $account_activation_code);
    13
        mysqli_stmt_bind_result($stmt_one, $username, $userActivationState);   
    14
        var_dump($email, $account_activation_code, $stmt_one, $userActivationState);   
    15
        if (mysqli_stmt_execute($stmt_one) && mysqli_stmt_fetch($stmt_one))
    16
        {      
    17
            if ($userActivationState != 0)
    18
            {          
    19
                echo "Since your account is already activated, why are you trying to activate it again ? Do not do that again and just login from <a href=\"login.php\">this webpage</a> next time! Make a note of that webpage, ok ?";
    20
                exit;
    21
            }
    22
            $userActivationState = 1;      
    23
            $stmt_two = mysqli_prepare($conn, "UPDATE users SET accounts_activations = ? WHERE usernames = ?");
    24
            mysqli_stmt_bind_param($stmt_two, 'is', $userActivationState, $username);      
    25
            var_dump($stmt_two, $userActivationState, $username);      
    26
            if (mysqli_stmt_execute($stmt_two))
    27
            {
    28
                echo "<h3 style='text-align:center'>Thank you for your confirming your email and activating your account.<br /> Redirecting you to the login page ...</h3>";
    29
                $_SESSION["user"] = $username;
    30
                header("location:home.php");
    31
                exit;
    32
            }
    33
        }
    34
        else
    35
        {
    36
            echo "FAILURE to UPDATE db";
    37
            exit;
    38
        }
    39
    }

  2. #2
    Join Date
    May 2016
    Location
    USA
    Posts
    860
    Thumbs Up/Down
    Received: 299/0
    Given: 23/0
    Thanks
    10
    Thanked 110 Times in 99 Posts
    It's failing at the mysqli_prepare.

    Add this line after the mysqli_prepare line and see what error message it shows.

    echo mysqli_error($conn);

  3. #3
    Join Date
    Jun 2017
    Posts
    6
    Thumbs Up/Down
    Received: 0/0
    Given: 1/0
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks Mod.
    Ok, I added the line as you suggested in 2 places.
    I get this shown:

    string(23) "[email protected]" string(40) "c1dfd96eea8cc2b62785275bca38ac261256e278" object(mysqli_stmt)#2 (10) { ["affected_rows"]=> int(0) ["insert_id"]=> int(0) ["num_rows"]=> int(0) ["param_count"]=> int(2) ["field_count"]=> int(2) ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["sqlstate"]=> string(5) "00000" ["id"]=> int(1) } NULL FAILURE to UPDATE db

    Here's the script:


    activate_account.php

    Code:
    <?php
    
    include 'config.php';
    
    if (!isset($_GET["email"], $_GET["account_activation_code"]) === true){
        $_SESSION['error'] = "Invalid Email Address! Invalid Account Activation Link! This email is not registered! Try registering an account if you do not already have one! <a href=\"register.php\">Register here!</a>";
        exit();
    } 
    else 
    {	
    	$email = htmlspecialchars($_GET['email']);	
    	$account_activation_code = htmlspecialchars($_GET['account_activation_code']);	
    	$stmt_one = mysqli_prepare($conn, "SELECT usernames, accounts_activations FROM users WHERE emails = ? AND accounts_activations_codes = ?");	
    	echo mysqli_error($conn);
    	mysqli_stmt_bind_param($stmt_one, 'si', $email,  $account_activation_code);	
    	mysqli_stmt_bind_result($stmt_one, $username, $userActivationState);	
    	var_dump($email, $account_activation_code, $stmt_one, $userActivationState);	
    	if (mysqli_stmt_execute($stmt_one) && mysqli_stmt_fetch($stmt_one))
    	{		
    		if ($userActivationState != 0)
    		{			
    			echo "Since your account is already activated, why are you trying to activate it again ? Do not do that again and just login from <a href=\"login.php\">this webpage</a> next time! Make a note of that webpage, ok ?";
    			exit;
    		}
    		
    		$userActivationState = 1;		
    		$stmt_two = mysqli_prepare($conn, "UPDATE users SET accounts_activations = ? WHERE usernames = ?");
    		echo mysqli_error($conn);
    		mysqli_stmt_bind_param($stmt_two, 'is', $userActivationState, $username);		
    		var_dump($stmt_two, $userActivationState, $username);		
    		if (mysqli_stmt_execute($stmt_two))
    		{
    			echo "<h3 style='text-align:center'>Thank you for your confirming your email and activating your account.<br /> Redirecting you to the login page ...</h3>";
    			$_SESSION["user"] = $username;
    			header("location:home.php");
    			exit;
    		}
    	} 
    	else 
    	{
    		echo "FAILURE to UPDATE db";
    		exit;
    	}
    }

    config.php

    Code:
    <?php
    
    /*
    ERROR HANDLING
    */
    declare(strict_types=1);
    ini_set('display_errors', '1');
    ini_set('display_startup_errors', '1');
    error_reporting(E_ALL);
    
    mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
    
    // session start
    if(!session_start()) {
    	session_start();
    }
    
    // include files
    include 'conn.php';
    include 'site_details.php';
    
    // include functions
    include 'functions.php';
    
    ?>

    conn.php

    Code:
    <?php
    
    $conn = mysqli_connect("localhost", "EDITED", "EDITED", "EDITED");
    
    if (!$conn) {
    	// message to use in development to see errors
    	die("Database error : " . mysqli_error($conn));
    
    	// user friendly message
    	// die("Database error.");
    	exit();
    }
    
    ?>

  4. #4
    Join Date
    May 2016
    Location
    USA
    Posts
    860
    Thumbs Up/Down
    Received: 299/0
    Given: 23/0
    Thanks
    10
    Thanked 110 Times in 99 Posts
    This line is valuating as FALSE. So we know the problem is above this line or with this line.

    if (mysqli_stmt_execute($stmt_one) && mysqli_stmt_fetch($stmt_one)) {

    I would break these two apart and add in some error checking to see what one is failing and possibly why.

    Also, you are running php 5 or 7 correct? And is mysqli extension setup on your PHP install?

  5. #5
    Join Date
    Jun 2017
    Posts
    6
    Thumbs Up/Down
    Received: 0/0
    Given: 1/0
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Error 500

    Yes, someone else suggested exactly the same as you but the result gave http error 500.
    Here was my update ...

    activate_account.php


    Code:
    <?php
    
    include 'config.php';
    
    if (!isset($_GET["email"], $_GET["account_activation_code"]) === true){
        $_SESSION['error'] = "Invalid Email Address! Invalid Account Activation Link! This email is not registered! Try registering an account if you do not already have one! <a href=\"register.php\">Register here!</a>";
        exit();
    } 
    else 
    {	
    	$email = htmlspecialchars($_GET['email']);	
    	$account_activation_code = htmlspecialchars($_GET['account_activation_code']);	
    	if ($stmt_one = mysqli_prepare($conn, "SELECT usernames, accounts_activations FROM users WHERE emails = ? AND accounts_activations_codes = ?");	
    		echo mysqli_error($conn);
    		mysqli_stmt_bind_param($stmt_one, 'si', $email,  $account_activation_code);	
    		mysqli_stmt_bind_result($stmt_one, $username, $userActivationState);	
    		var_dump($email, $account_activation_code, $stmt_one, $userActivationState);
    	}
    	else
    	{
    		echo "Mysqli prepare Failed!";
    		exit;
    	}	
    	
    	if (mysqli_stmt_execute($stmt_one)) 
    	{
    		echo success: mysqli_stmt_execute($stmt_one);
    	}
    	else
    	{
    		echo failure: mysqli_stmt_execute($stmt_one);
    	}
        
        if( mysqli_stmt_fetch($stmt_one)) 
    	{
    		echo success: mysqli_stmt_fetch($stmt_one);
    	}
    	else
    	{
    		echo failure: mysqli_stmt_fetch($stmt_one);	
    	}
    		if ($userActivationState != 0)
    		{	
    			echo "Since your account is already activated, why are you trying to activate it again ? Do not do that again and just login from <a href=\"login.php\">this webpage</a> next time! Make a note of that webpage, ok ?";
    			exit;
    		}
    		
    		$userActivationState = 1;
    		
    		$stmt_two = mysqli_prepare($conn, "UPDATE users SET accounts_activations = ? WHERE usernames = ?");
    		echo mysqli_error($conn);
    		mysqli_stmt_bind_param($stmt_two, 'is', $userActivationState, $username);		
    		var_dump($stmt_two, $userActivationState, $username);		
    		if (mysqli_stmt_execute($stmt_two))
    		{
    			echo "<h3 style='text-align:center'>Thank you for your confirming your email and activating your account.<br /> Redirecting you to the login page ...</h3>";
    			$_SESSION["user"] = $username;
    			header("location:home.php");
    			exit;
    		}
    	} 
    	else 
    	{
    		echo "FAILURE to UPDATE db";
    		exit;
    	}
    }

    Mysqli works on my webhost. Been using it all this time. Use php 7.

  6. #6
    Join Date
    May 2016
    Location
    USA
    Posts
    860
    Thumbs Up/Down
    Received: 299/0
    Given: 23/0
    Thanks
    10
    Thanked 110 Times in 99 Posts
    Your echo commands are formatted wrong.

    echo success: mysqli_stmt_execute($stmt_one);

    Should be

    echo 'success: mysqli_stmt_execute($stmt_one)';

    Add begin and end ' single quotes to each one.

  7. #7
    Join Date
    Jun 2017
    Posts
    6
    Thumbs Up/Down
    Received: 0/0
    Given: 1/0
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I don't know why my following version is still showing http Error 500.

    Code:
    <?php
    
    include 'config.php';
    
    if (!isset($_GET["email"], $_GET["account_activation_code"]) === true){
        $_SESSION['error'] = "Invalid Email Address! Invalid Account Activation Link! This email is not registered! Try registering an account if you do not already have one! <a href=\"register.php\">Register here!</a>";
        exit();
    } 
    else 
    {	
    	$email = htmlspecialchars($_GET['email']);	
    	$account_activation_code = htmlspecialchars($_GET['account_activation_code']);	
    	if ($stmt_one = mysqli_prepare($conn, "SELECT usernames, accounts_activations FROM users WHERE emails = ? AND accounts_activations_codes = ?");	
    		echo mysqli_error($conn);
    		echo 'Success: Mysqli Prepare passed!';
    		mysqli_stmt_bind_param($stmt_one, 'si', $email,  $account_activation_code);	
    		mysqli_stmt_bind_result($stmt_one, $username, $userActivationState);	
    		var_dump($email, $account_activation_code, $stmt_one, $userActivationState);
    	}
    	else
    	{
    		echo "Failure: Mysqli Prepare Failed!";
    		exit;
    	}	
    	if (mysqli_stmt_execute($stmt_one)) 
    	{
    		echo 'Success: Mysqli_stmt_execute($stmt_one)';
    	}
    	else
    	{
    		echo 'Failure: Mysqli_stmt_execute($stmt_one)';
    		exit;
    	}    
        if( mysqli_stmt_fetch($stmt_one)) 
    	{
    		echo 'Success: Mysqli_stmt_fetch($stmt_one)';
    	}
    	else
    	{
    		echo 'Failure: Mysqli_stmt_fetch($stmt_one)';
    		exit;
    	}
    	if ($userActivationState != 0)
    	{	
    		echo "Since your account is already activated, why are you trying to activate it again ? Do not do that again and just login from <a href=\"login.php\">this webpage</a> next time! Make a note of that webpage, ok ?";
    		exit;
    	}
    	else
    	{
    		$userActivationState = 1;
    		var_dump($stmt_one);
    		
    		$stmt_two = mysqli_prepare($conn, "UPDATE users SET accounts_activations = ? WHERE usernames = ?");
    		echo mysqli_error($conn);
    		mysqli_stmt_bind_param($stmt_two, 'is', $userActivationState, $username);		
    		var_dump($stmt_two, $userActivationState, $username);		
    		if (mysqli_stmt_execute($stmt_two))
    		{
    			echo "<h3 style='text-align:center'>Thank you for your confirming your email and activating your account.<br /> Redirecting you to the login page ...</h3>";
    			$_SESSION["user"] = $username;
    			header("location:home.php");
    			exit;
    		}
    		else
    		{
    			echo 'Failure: Mysqli_stmt_fetch($stmt_one)';
    			exit;
    		}
    	} 
    	else 
    	{
    		echo "FAILURE to UPDATE db";
    		exit;
    	}
    }
    
    ?>

  8. #8
    Join Date
    May 2016
    Location
    USA
    Posts
    860
    Thumbs Up/Down
    Received: 299/0
    Given: 23/0
    Thanks
    10
    Thanked 110 Times in 99 Posts
    Look in the folder the script is executing from and see if you have an error log file. That may give more details on why it is giving an error. If you don't see one, check in cpanel for an error log viewer or tale log viewer.

Newer Threads

  1. PenguinManiac
    vishwa
    Replies: 3 | Views: 124
    Last post by vishwa, 08-15-2017, 10:30 AM
  2. yishak1412
    Hello
    By yishak1412 in forum New Member Introductions
    ulterios
    Replies: 3 | Views: 166
    Last post by ulterios, 08-15-2017, 11:32 PM
  3. pizzalover
    Wyvh
    Replies: 3 | Views: 81
    Last post by Wyvh, 08-14-2017, 07:58 PM
  4. Wyvh
    Wyvh
    Replies: 2 | Views: 129
    Last post by Wyvh, Yesterday, 07:33 PM
  5. Izul_Link_Growth
    Izul_Link_Growth
    Replies: 0 | Views: 54
    Last post by Izul_Link_Growth, 08-15-2017, 07:44 AM

Older Threads

  1. PenguinManiac
    manmad
    Replies: 3 | Views: 177
    Last post by manmad, Yesterday, 10:41 AM
  2. stoneman
    fayeseom
    Replies: 1 | Views: 96
    Last post by fayeseom, 08-16-2017, 11:12 AM
  3. PenguinManiac
    Gazoo
    Replies: 10 | Views: 266
    Last post by Gazoo, 08-20-2017, 05:21 AM
  4. chanel majic
    stoneman
    Replies: 2 | Views: 150
    Last post by stoneman, 08-12-2017, 02:59 PM
  5. Gazoo
    spartan14
    Replies: 4 | Views: 73
    Last post by spartan14, 08-12-2017, 06:09 AM

Latest Threads

  1. jessicarousey
    Permanently deleting an account
    By jessicarousey in forum Facebook
    ulterios
    Replies: 1 | Views: 26
    Last post by ulterios, Today, 02:36 AM
  2. malaklana
    Hey Everyone!
    By malaklana in forum New Member Introductions
    ulterios
    Replies: 2 | Views: 26
    Last post by ulterios, Today, 02:57 AM
  3. TomCo
    Rob Whisonant
    Replies: 1 | Views: 41
    Last post by Rob Whisonant, 08-22-2017, 07:25 PM
  4. etdigital
    centurion
    Replies: 1 | Views: 49
    Last post by centurion, 08-22-2017, 09:44 AM
  5. WebsiteIntegrations
    Selling HTML To WordPress, HTML To WHMCS, HTML To Responsive
    By WebsiteIntegrations in forum Templates
    WebsiteIntegrations
    Replies: 0 | Views: 181
    Last post by WebsiteIntegrations, 08-20-2017, 06:09 AM

Similar Threads

  1. mitali
    Sam
    Replies: 4 | Views: 551
    Last post by Sam, 01-24-2017, 08:21 PM
  2. mitali
    skullofskill
    Replies: 10 | Views: 802
    Last post by skullofskill, 01-10-2017, 07:23 AM
  3. pathfinder
    Rob Whisonant
    Replies: 4 | Views: 500
    Last post by Rob Whisonant, 01-04-2017, 03:43 AM
  4. denvercardonations
    Namecheap and error 508's
    By denvercardonations in forum Web Hosting
    RDO Servers
    Replies: 6 | Views: 1166
    Last post by RDO Servers, 03-02-2016, 11:57 AM
  5. lindanancy
    Tommy
    Replies: 3 | Views: 1416
    Last post by Tommy, 02-20-2013, 03:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Internet Marketing Forum

Webmaster Sun is a forum where you’ll find in-depth discussions and resources to help you succeed on the web whether you are new or experienced. You’ll find it all here. With topics ranging from internet marketing, search engine optimization, social networking, make money online, web hosting, affiliate marketing as well as hands-on technical support for web design, programming and more. We are a growing community of like-minded people that is keen to help and support each other with ambitions and online endeavors. Learn and grow, make friends and contacts for life.

Come Hang Out With Us

    Facebook Twitter Webmaster Forum Google+

    Webmaster Sun Logo
Copyright ©2012 - 2017, WebmasterSun.com. All rights reserved. Internet marketing forum for internet marketers, webmasters, web hosting providers, designers and affiliate marketers.

Welcome to Webmaster Sun

The World's Number 1 Webmaster Community, SEO and Marketplace

Log in!

Continue with Facebook
Continue With Email. By signing up you indicate that you have read and agree to the Terms of Service and Privacy Policy.

Sign in Manually

Need an account? Sign up now!