PHP ERROR - Prepared queries [closed]

4

Good morning everyone, I'm starting in PHP, I follow a course through youtube. I'm studying prepared consultations. I have a form that does a query in the DB, however, when entering the data, the following error message appears:

  

Warning: mysqli_stmt_bind_param () expects parameter 1 to be   mysqli_stmt, boolean given in

Below the code:

<?php 

        $c_art = $_GET["c_art"];

        $secc = $_GET["secc"];

        $n_art = $_GET["n_art"];

        $pre = $_GET["pre"];

        $fec = $_GET["fec"];

        $imp = $_GET["imp"];

        $p_orig = $_GET["p_ori"];

        include ("dados_banco.php");

        $conexion=mysqli_connect($db_host, $db_usuario, $db_contra);

        if (mysqli_connect_errno()) {

            echo "Fallo al conectar con la BBDD";

            exit();

        }

        mysqli_select_db($conexion,$db_nombre) or die("No se encunetra la  BBDD");

        mysqli_set_charset($conexion, "utf-8");

        $sql="INSERT INTO productos (CODIGOARTÍCULO, SECCION, NOMBREARTICULO, PRECIO, FECHA, IMPORTADO, PAISDEORIGEN) VALUES (?,?,?,?,?,?,?)";

        $resultado=mysqli_prepare($conexion, $sql);

        $ok=mysqli_stmt_bind_param($resultado, "sssssss", $c_art, $secc, $n_art, $pre, $fec, $imp, $p_ori);

        $ok=mysqli_stmt_execute($resultado);

        if($ok==false){

            echo "Error al ejecutar la consulta";

        }else{

            //$ok=mysqli_stmt_bind_result($resultado, $codigo, $seccion, $precio, $pais);

            echo "Agregado nuevo registro";

            /*while(mysqli_stmt_fetch($resultado)){

                echo $codigo . " " . $seccion . " " . $precio . " " . $pais . "<br>";

            }*/

            mysqli_stmt_close($resultado);
        }


     ?>
    
asked by anonymous 20.06.2016 / 14:36

1 answer

2

Good morning, the problem is this line:

$ok=mysqli_stmt_bind_param($resultado, "sssssss", $c_art, $secc, $n_art, $pre, $fec, $imp, $p_ori);

According to your query, 7 values are expected and you are passing 9:

INSERT INTO productos (CODIGOARTÍCULO, SECCION, NOMBREARTICULO, PRECIO, FECHA, IMPORTADO, PAISDEORIGEN) VALUES (?,?,?,?,?,?,?)
    
18.10.2016 / 13:47