NathanLedet Posted April 27, 2009 Share Posted April 27, 2009 I'm building a little animal management system where people can update records of animals they keep. I have given the ability to upload an image - and when a user edits an animal, and chooses NOT to upload a new image, then the image initially chosen will not change. So, in my code to process the submission, I have the following SQL query that is running into an unexpected T_IF. $sql = "UPDATE rcms SET `animal_id` = '{$animalid}', `type` = '{$animaltype}', `weight` = '{$animalweight}', `birthday` = '{$animalbday}', `description` = '{$animaldescription}'" . if ($filename != NULL){ ", `image` = '{$filename}'" }. "WHERE id='{$id}' LIMIT 1"; I have other code that process the image if it's there, or sets the $filename variable to NULL if the file field is left blank. So, essentially, All I'm trying to do is say if $filename is not NULL (has a name of a new file) - add that snippet of code so that it will update in the database. Quote Link to comment Share on other sites More sharing options...
Mchl Posted April 27, 2009 Share Posted April 27, 2009 You can't use concatenation like this. Try: $sql = "UPDATE rcms SET `animal_id` = '{$animalid}', `type` = '{$animaltype}', `weight` = '{$animalweight}', `birthday` = '{$animalbday}', `description` = '{$animaldescription}'" .(($filename != NULL) ? ", `image` = '{$filename}'" : ""). "WHERE id='{$id}' LIMIT 1"; Quote Link to comment 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.