I've been sitting on the same small problem now for over 10 hours, so it's time to ask stackoverflow! I'm connected to the database but when calling mysqli_stmt_bind_param I get "invalid object or resource".
I have prepared the following procedures that are trowing the issue in PHP languaje. I have commented the code below explaining what I am trying to do.
<?php
include("conexie.php");
$sentencia = mysqli_stmt_init($enlace);
if (mysqli_stmt_prepare($sentencia, "INSERT INTO actividad 
                                        (codalt,actividad) VALUES (?,?)")) 
{
    mysqli_stmt_bind_param($sentencia, "is",$alternativa,$actividad);//link the parameters with the sentence. Insert
    mysqli_stmt_execute($sentencia);//execute the sentence
    mysqli_stmt_close($sentencia);//close the sentence
    $codact=mysqli_insert_id($enlace);//check the latest raw inserted in the database
    if ($codact==0){
        echo "No ha podido copiarse la actividad, verifica que no estaba copiada";
    }else{
        //when success we retrieve the results from the previous actions
        $sentencia = mysqli_stmt_init($enlace);
        if (mysqli_stmt_prepare($sentencia, 'SELECT titulo, observa, lugar 
                                             FROM acto WHERE codact=?')) 
        {
            mysqli_stmt_bind_param($sentencia, 'i', $codact0);//link the parameters with the sentence. Retrieve
            mysqli_stmt_execute($sentencia);// execute the SQL
                mysqli_stmt_bind_result($sentencia,$titulo,$observa,$lugar);//populate the results to the variables
            //Go through the results
            while (mysqli_stmt_fetch($sentencia)){
                $estado=0;
                Echo ''.$codact.''.$titulo.'<>'.$observa.'<>'.$lugar.'<>'.$estado;//verify the variables are different to null
                if (mysqli_connect_errno($enlace)){
                    echo "Failed to connect to MySQL: " . mysqli_connect_error();
                }
                $stmt = mysqli_stmt_init($enlace);
                $query =  "INSERT INTO acto 
                            (codact,titulo,observa,lugar,estado) 
                            VALUES (?, ?, ?, ?, ?)";
                mysqli_stmt_prepare($stmt, $query);
                mysqli_stmt_bind_param($stmt, "isssi", 
                    $codact,$titulo,$observa,
                    $lugar,$estado);//This line (761) throws the error.
                if(mysqli_stmt_execute($stmt)){
                    mysqli_close($stmt);//This line (762) throws the error.
                }
            }
            mysqli_stmt_close($sentencia);// Close the method
        }
    }
}
?>
The description of the error is as follows. Including the results of the SQL
1995
Record 1 var 2
Record 1 var 3
Record 1 var 4
0
Warning: mysqli_stmt_bind_param(): invalid object or resource mysqli_stmt in D:\xampp\htdocs\AAAAA\agenda\agenda.php on line 761
Warning: mysqli_stmt_execute(): invalid object or resource mysqli_stmt in D:\xampp\htdocs\AAAAA\agenda\agenda.php on line 762
1995
Record 2 var 2
Record 2 var 3
Record 2 var 4
0
Warning: mysqli_stmt_bind_param(): invalid object or resource mysqli_stmt in D:\xampp\htdocs\AAAAA\agenda\agenda.php on line 761
Warning: mysqli_stmt_execute(): invalid object or resource mysqli_stmt in D:\xampp\htdocs\AAAAA\agenda\agenda.php on line 762
 
    