1
votes
    $id = DB::table('utilisateur')
        ->select('idUtlstr')
        ->where('email','=',$request ->input("email"))
        ->get();

    DB::table('client')->insert(
        [
            'idClient' => $id, 
            'nbrSignl' => 0,
            'numPermis' => 0, 
            'quest1' => 'vide',
            'quest2' => 'vide',
            'quest3'=> 'vide',
            'datePermis' => '2000-01-01',
            'numCompte' => 0 ,
            'blocage' => 'non' 
        ]
    );

SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '[{"idUtlstr":25}]' for column 'idClient' at row 1 (SQL: insert into client (idClient, nbrSignl, numPermis, quest1, quest2, quest3, datePermis, numCompte, blocage) values ([{"idUtlstr":25}], 0, 0, vide, vide, vide, 2000-01-01, 0, non))

4
Looks like the error message shows you exactly which col is not an integer... What's your question?WillardSolutions
when i try to put what is inside the $id in my the column 'idClient' ii get this error i didn't understand how the get the the value 25 from (idUtlstr) that it is saved in $idaymen medjader
It's a simple object array. See @flash Thunder's answer belowWillardSolutions
this is my first time working on this ... thanx manaymen medjader

4 Answers

2
votes

This is because $id is not an integer after your database request. Your query returns an object that is element collection and you need to get it properly...

Do var_dump($id) and you will see that it returns stdClass.

Use this after query:

$my_id = $id{0}->idUtlstr

And use that variable in second query.

1
votes

Try it

$utilisateur = DB::table('utilisateur')
    ->select('idUtlstr')
    ->where('email',$request->input("email"))
    ->first();
if (!empty($utilisateur)) {
   $id = $utilisateur->idUtlstr;  
   $data = [
      'idClient' => $id, 
      'nbrSignl' => 0,
      'numPermis' => 0, 
      'quest1' => 'vide',
      'quest2' => 'vide',
      'quest3'=> 'vide',
      'datePermis' => '2000-01-01',
      'numCompte' => 0 ,
      'blocage' => 'non' 
   ];
   DB::table('client')->insert($data);
}
0
votes

Use This, I hope it will works.

$id = DB::table('utilisateur')
            ->select('idUtlstr')
            ->where('email','=',$request ->input("email"))
            ->first();

        DB::table('client')->insert(
            [
                'idClient' => $id->idUtlstr, 
                'nbrSignl' => 0,
                'numPermis' => 0, 
                'quest1' => 'vide',
                'quest2' => 'vide',
                'quest3'=> 'vide',
                'datePermis' => '2000-01-01',
                'numCompte' => 0 ,
                'blocage' => 'non' 
            ]
        );
0
votes

This is because $id is an integer and the query returns an object. For example the $id value equals to 2 in your database, but the query returns it as '{"id":2}' not 2.

What you should do is add a second variable to get the id:

$myid = $id->id

This equals to $myid = 2. Then you can use $myid for your second query and everything will work fine.

Based on your code, this should work:

$id = DB::table('utilisateur')
    ->select('idUtlstr')
    ->where('email','=',$request ->input("email"))
    ->get();
    $myid = $id->id

DB::table('client')->insert(
    [
        'idClient' => $myid, 
        'nbrSignl' => 0,
        'numPermis' => 0, 
        'quest1' => 'vide',
        'quest2' => 'vide',
        'quest3'=> 'vide',
        'datePermis' => '2000-01-01',
        'numCompte' => 0 ,
        'blocage' => 'non' 
    ]
);