Home > Software engineering >  SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' in
SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' in

Time:04-17

I am trying to updateOrCreate some data(to insert multiple row), but is shows the following error :

SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' (SQL: select * from test_questions where (0= question_id and1 = 1650168432072) limit 1)

my code from the controller is :

foreach($request->questions as $key => $no)
        {
            $input['question_number']     = $request->questions[$key]['question_number'];
            $input['test_id']             = $request->test_id;
            $input['question']            = $request->questions[$key]['question'];
            $input['answer']              = $request->questions[$key]['answer'];
            $input['correct_option_name'] = $request->questions[$key]['correct_option_name'];
            $input['question_id']         = $request->questions[$key]['question_id']; 
            $create_question = testQuestion::updateOrCreate(['question_id',$request- 
            >questions[$key]['question_id']],$input);

        }

And from $request->all()

  Array
  (
     [_token] => h9I1ghP5cz8mZExuYgwwGHFePVBKMsiamDwslMA9
     [test_id] => 50
     [questions] => Array
    (
        [1650168432072] => Array
            (
                [question_number] => 1
                [question_id] => 1650168432072
                [question] => sdasd
                [answer] => asdasdasd
                [correct_option_name] => a
                [option] => Array
                    (
                        [180] => Array
                            (
                                [option_number] =>  option_number 
                                [question_num] =>  q_num 
                                [op_question_id] => 1650168432072
                                [question_id] => 180
                                [correct_answer] => 
                                [option_name] => a
                                [option_id] => 1650168432072852
                                [option_content] => asdsd
                            )

                        [181] => Array
                            (
                                [option_number] =>  option_number 
                                [question_num] =>  q_num 
                                [op_question_id] => 1650168432072
                                [question_id] => 181
                                [option_name] => b
                                [option_id] => 1650168432072706
                                [option_content] => asdsad
                            )

                    )

            )

        [1650168444214] => Array
            (
                [question_number] => 2
                [question_id] => 1650168444214
                [question] => asdasds
                [answer] => asdsd
                [correct_option_name] => b
                [option] => Array
                    (
                        [182] => Array
                            (
                                [option_number] =>  option_number 
                                [question_num] =>  q_num 
                                [op_question_id] => 1650168444214
                                [question_id] => 182
                                [option_name] => a
                                [option_id] => 1650168444214112
                                [option_content] => sdasd
                            )

                        [183] => Array
                            (
                                [option_number] =>  option_number 
                                [question_num] =>  q_num 
                                [op_question_id] => 1650168444214
                                [question_id] => 183
                                [correct_answer] => 
                                [option_name] => b
                                [option_id] => 1650168444214881
                                [option_content] => sadsd
                            )

                        [1] => Array
                            (
                                [option_number] => 1
                                [question_num] => 1650168444214
                                [op_question_id] => 1650168444214
                                [option_id] => 1650168444214261
                                [option_name] => c
                                [option_content] => sadas
                            )

                        )

                   )

             )

         [files] => 
     )

I am adding some dummy text to avoid "mostly code" problem : Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,

CodePudding user response:

you sould use :

testQuestion::updateOrCreate(['question_id' => $request->questions[$key]['question_id']],$input)

instead of :

testQuestion::updateOrCreate(['question_id',$request->questions[$key]['question_id']],$input);
  • Related