PHP BUG - Prepared queries

Asked

Viewed 99 times

4

Good morning everyone, I’m starting in PHP, I follow a course through youtube. I’m studying prepared queries. I have a form that makes a query in the BD, 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);
        }


     ?>
  • 1

    $resultado is false soon fails the query.

  • Do $resultado=mysqli_prepare($conexion, $sql) or die(mysqli_error($conexion)); and put the error message.

  • 1

    Laerte, I did the test q asked and noticed that the problem was in some columns of the bank.. mt thank you, it worked! hugs.

  • I believe that in the spine with acute accent in the name, correct?

  • No, Jhonatan.. the course I am following is in Spanish (I also found it odd that he use accents), and following as it is presented.. was in other field the problem.. obgd by the help

1 answer

2

Good morning, the problem is on that 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 (?,?,?,?,?,?,?)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.