Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

filipe1221's avatar

Check if query update

I Have this

$update=DB::table('pages')->where('id', $data['id'])->update(array('value' => $values));

Now this is updating correct and i want check if that was correctley update. i try this

if ($update>0) but sometimes gives 0 however query was successfuly.

Thanks

0 likes
7 replies
dleroari's avatar

I am not sure how you have structured your conditional if-statement. However, when the query updates the value(s), it returns true. Everything except that means it failed. In that case, simply place the variable in an if-statement like shown below:

Try this:

// $udpate is true
if($update){

    // Update was successful

}else{
    
    // Update failed

}


1 like
Cronix's avatar

It will throw an error if it fails, so you can assume it went ok if there wasn't an exception or error thrown.

2 likes
dleroari's avatar

What exactly fails, can you do a dd($update) to check what value you receive when it fails, is it null, false etc.

dleroari's avatar

Last question, have you checked visually if the record is updated?

Please or to participate in this conversation.