SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Error in mysqli

  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2010
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Error in mysqli

    hi guys

    i get an error in this code (comment in the code):

    Code:
    if (checkBd ($sql, $db, $valor, $codePass)){
    
        ($sql = $db->prepare("UPDATE users SET activation = ? WHERE activationLink=?"));
    
        $valor="1";
        $sql->bind_param('is', $valor, $codePass);
    
        $sql->execute();
    
        $sql->bind_result($valor, $codePass); //Warning: mysqli_stmt::bind_result() [mysqli-stmt.bind-result]: Number of bind variables doesn't match number of fields in prepared statement 
    
        if ($sql->fetch()) {
            header("location: index.php");
            return true;
        }
        else {
            echo "no";
            return false;
        }
    $sql->close();
    $db->close();
    }
    what is the possible problem in the script? an another question, is this way correct to update a boolean?

    thanks

  2. #2
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    I am not 100% sure, my suggestion is going solve your issue..

    But First you are trying to update column with (update query) using bind_param. Which is going working fine, i guess.
    And then you are trying to fetch record using bind_result on update query and this line is not going to work as update query is not returning any record set.

    Any ways bind_result works on number of column return as a result set of query. Update query is going to return true or false so instead of trying bind_result go for fetch() function directly.

    Let me know if it works.

    Cheers

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2010
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tejash View Post
    Hi

    I am not 100% sure, my suggestion is going solve your issue..

    But First you are trying to update column with (update query) using bind_param. Which is going working fine, i guess.
    And then you are trying to fetch record using bind_result on update query and this line is not going to work as update query is not returning any record set.

    Any ways bind_result works on number of column return as a result set of query. Update query is going to return true or false so instead of trying bind_result go for fetch() function directly.

    Let me know if it works.

    Cheers
    thanks for your answer. If i use fetch() the code doesn't work, then I took it.

    Now works well

    my final code is:
    Code:
    if (checkBd ($sql, $db, $codePass)){
    
    	$valor=1;
    	($sql = $db->prepare("UPDATE users SET activation=? WHERE activationLink=?"));
    
    	$sql->bind_param('is', $valor, $codePass);
    
    	$sql->execute();
    	header("location: index.php");
    	return true;
    }
    else {
    	echo "no";
    	return false;
    }
    $sql->close();
    $db->close();

    thanks!


Bookmarks

Posting Permissions

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