0

I'm trying to insert datas in my bdd btw of this (too) huge request, i've modified it many times and now, i'm stuck on this error for a while... my request is really simple and i nerver had this type of error...

<?php

    require "functions.php";
    require_once "../conf.inc.php";


    if(count($_POST)==19){

           if (is_numeric($_POST['inputsteak'])
        && is_numeric($_POST['inputfilet'])
        && is_numeric($_POST['inputviandehachee'])
        && is_numeric($_POST['inputlangue'])
        && is_numeric($_POST['inputpoitrine'])
        && is_numeric($_POST['inputentrecote'])
        && is_numeric($_POST['inputaile'])
        && is_numeric($_POST['inputcuisse'])
        && is_numeric($_POST['inputblanc'])
        && is_numeric($_POST['inputpouletentier'])
        && is_numeric($_POST['inputcoteporc'])
        && is_numeric($_POST['inputsaucisson'])
        && is_numeric($_POST['inputjambonblanc'])
        && is_numeric($_POST['inputsaucisse'])
        && is_numeric($_POST['inputandouillette'])
        && is_numeric($_POST['inputboudinnoir'])
        && is_numeric($_POST['inputboudinblanc'])
        && is_numeric($_POST['inputtrippe'])
        && is_numeric($_POST['inputlardon']))
        {
            $connection = connectDB();
                $request = $connection->prepare("SELECT user_id FROM users WHERE users.email = :t");
                $request->execute(['t'=>'antoine.decrouez@yahoo.fr' ]);
                $result = $request->fetchALL(PDO::FETCH_ASSOC);

                $query = $connection->prepare("INSERT INTO fridge(user_id, ing_id, quantity) VALUES ((:t,:a1,:a),(:t,:a2,:b),(:t,:a3,:c),(:t,:a4,:d),(:t,:a5,:e),(:t,:a6,:f),(:t,:a7,:g),(:t,:a8,:h),(:t,:a9,:i),(:t,:a10,:j),(:t,:a11,:k),(:t,:a12,:l),(:t,:a13,:m),(:t,:a14,:n),(:t,:a15,:o),(:t,:a16,:p),(:t,:a17,:q),(:t,:a18,:r),(:t,:a19,:s))");
                $query->execute([
                              "a1"=>3,
                              "a"=>$_POST['inputsteak'],
                              "a2"=>4,
                              "b"=>$_POST['inputfilet'],
                              "a3"=>5,
                              "c"=>$_POST['inputviandehachee'],
                              "a4"=>6,
                              "d"=>$_POST['inputlangue'],
                              "a5"=>7,
                              "e"=>$_POST['inputpoitrine'],
                              "a6"=>8,
                              "f"=>$_POST['inputentrecote'],
                              "a7"=>9,
                              "g"=>$_POST['inputaile'],
                              "a8"=>10,
                              "h"=>$_POST['inputcuisse'],
                              "a9"=>11,
                              "i"=>$_POST['inputblanc'],
                              "a10"=>12,
                              "j"=>$_POST['inputpouletentier'],
                              "a11"=>13,
                              "k"=>$_POST['inputcoteporc'],
                              "a12"=>14,
                              "l"=>$_POST['inputsaucisson'],
                              "a13"=>15,
                              "m"=>$_POST['inputjambonblanc'],
                              "a14"=>16,
                              "n"=>$_POST['inputsaucisse'],
                              "a15"=>17,
                              "o"=>$_POST['inputandouillette'],
                              "a16"=>18,
                              "p"=>$_POST['inputboudinnoir'],
                              "a17"=>19,
                              "q"=>$_POST['inputboudinblanc'],
                              "a18"=>20,
                              "r"=>$_POST['inputtrippe'],
                              "a19"=>21,
                              "s"=>$_POST['inputlardon'],
                              "t" => '1'

                          ]);

        }else{
                echo "<p style='color=red;'>veuillez rentrer les quantité en valeurs nuériques</p>";
        }

}else{

    die("tentative de hack");

}

Here is my request (yeah my variants are in french sorry xD ) My bdd table fridge is just composed by user_id, ing_id and quantity

Does someone know what it is ? :(

Tonio San
  • 3
  • 1
  • Possible duplicate of [PDO Parameterized Query - Reuse named placeholders?](https://stackoverflow.com/questions/2432084/pdo-parameterized-query-reuse-named-placeholders) – Sean Jul 01 '18 at 01:38
  • 1
    Do you have emulation on? `You must include a unique parameter marker for each value you wish to pass in to the statement when you call PDOStatement::execute(). You cannot use a named parameter marker of the same name more than once in a prepared statement, unless emulation mode is on.` – user3783243 Jul 01 '18 at 01:41

1 Answers1

0

By me you have wrong SQL query. By documentation insert multiple rows looks like this: INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);.

Remove the outer () from your VALUES clause. A multi-row VALUES clause is not () enclosed, but each comma-separated row group is () enclosed as in VALUES (1,2,3),(4,5,6),(7,8,9).

step
  • 2,254
  • 2
  • 23
  • 45