Andy-H Posted January 20, 2012 Share Posted January 20, 2012 $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 Quote Link to comment https://forums.phpfreaks.com/topic/255436-is-there-a-way-to-do-this/ Share on other sites More sharing options...
Andy-H Posted January 20, 2012 Author Share Posted January 20, 2012 Problem solved, it worked fine but I used the wrong statement to pull the vehicleID from because I'm a dick lol Quote Link to comment https://forums.phpfreaks.com/topic/255436-is-there-a-way-to-do-this/#findComment-1309629 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.