Jump to content

Is there a way to do this?


Andy-H

Recommended Posts


                  $vehicleID = $check->fetchColumn(0);
                  $stmt = $dbh->prepare("UPDATE caravans SET 
                                    make  = (IF(LENGTH(:make), :make, make)), 
                                    model = (IF(LENGTH(:model),:model, model)), 
                                    type  = (IF(LENGTH(:type), :type, type)), 
                                    axle  = (IF(LENGTH(:axle), :axle, axle)),
                                    CRis  = (IF(LENGTH(:CRis), :CRis, CRis))
                                WHERE id = :vID LIMIT 1");
                  $stmt->bindParam(':make',  $data['make'],  PDO::PARAM_STR, strlen($data['make']));
                  $stmt->bindParam(':model', $data['model'], PDO::PARAM_STR, strlen($data['model']));
                  $stmt->bindParam(':type',  $data['type'],  PDO::PARAM_STR, strlen($data['type']));
                  $stmt->bindParam(':axle',  $data['axle'],  PDO::PARAM_STR, strlen($data['axle']));
                  $stmt->bindParam(':CRis',  $data['CRis'],  PDO::PARAM_STR, strlen($data['CRis']));
                  $stmt->bindParam(':vID',   $vehicleID,     PDO::PARAM_INT);
                  $stmt->execute();

Basically, I want the fields to update if the $data contains a value for it, the above doesn't work.

 

 

Thanks for any help

Link to comment
https://forums.phpfreaks.com/topic/255436-is-there-a-way-to-do-this/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.