$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))
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.
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);
}
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'
]
);
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'
]
);