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

jamols09's avatar

SQLSTATE[IMSSP]: The active result for the query contains no fields.

I have this code on my controller that updates the table. The controller runs but the issue is that its giving me error.

$query = "UPDATE dispatch SET 
                        deptId = '$department',
                        type= '$type', 
                        destination = '$dest',
                        purpose = '$purpose', 
                        passengers = '$pass', 
                        odometer_start = '$odom_s',
                        dateStart = '$app_date', 
                        vehicle_cost_code = '$vcode', 
                        unitId = '21' 
                    WHERE 
                        tripTicket = '$ticket'";
                            
            DB::select($query);

Error SQLSTATE[IMSSP]: The active result for the query contains no fields. (SQL: UPDATE dispatch SET deptId = 'Mine Operation', type= ' BACKHOE #8 (KOMATSU PC 200)', destination = 'CIVIL WORKS|MINE BATCHING PLANT', ...)

0 likes
2 replies
rodrigo.pedra's avatar

As this is a UPDATE and not a SELECT you should use:

DB::statement(query);

Also @sergiu17 's shared a link to docs with a better alternative:

https://laravel.com/docs/8.x/database#running-an-update-statement

You might have to tweak your query to use bindings instead of inlinig the values in the query, but that will also prevent SQL injection.

    DB::update('UPDATE dispatch 
        SET
            deptId = ?,
            type= ?,
            destination = ?,
            purpose = ?,
            passengers = ?,
            odometer_start = ?,
            dateStart = ?,
            vehicle_cost_code = ?,
            unitId = ?
        WHERE
            tripTicket = ?', [
        $department,
        $type,
        $dest,
        $purpose,
        $pass,
        $odom_s,
        $app_date,
        $vcode,
        21,
        $ticket,
    ]);

I was not aware of that option, thanks @sergiu17 .

1 like

Please or to participate in this conversation.