number of variables does not match the mysqli parameters

1

I'm trying to do a select "binded" but this is returning the following error Warning: mysqli_stmt :: bind_param () [mysqli-stmt.bind-param]: Number of variables does not match number of parameters in prepared statement in

    $query = "SELECT * FROM duelos WHERE status='desafiado' AND desafiado='?'";
    $statement = $mysqli->prepare($query);

    //bind parameters for markers, where (s = string, i = integer, d = double,  b = blob)
    $statement->bind_param('s',$desafiante);
    $statement->execute();

    if($statement->execute()){
        print 'Voce foi desafiado por $desafiante <br> Aceitar o desafio? <br> Sim  -  Nao';
    }else{
        print 'Nada a relatar';
    }
    $statement->close();
    
asked by anonymous 14.02.2016 / 16:46

1 answer

1

In your query there is no placeholder, the values should not be passed directly but instead exchanged for only queries ( ? ) it is not necessary to use single quotation marks to escape them when using prepared statements.

Change:

$query = "SELECT * FROM d
$statement->bind_param(si, $status ,$iddesafiante);uelos WHERE status='desafiado' AND iddesafiado='$iddesafiante'";

By:

$query = "SELECT * FROM duelos WHERE status = ? AND iddesafiado = ?";
$statement->bind_param('si', $status ,$iddesafiante);
    
14.02.2016 / 16:48