Snaggle Posted July 1, 2010 Share Posted July 1, 2010 I have a page on my website where Admins can update other users information. Problem is, if they leave a field blank, it still inserts into the SQL database. So the problem is, if they leave the email field blank, it will erase the email stored in the database. How do I avoid blank fields deleting data? Quote Link to comment https://forums.phpfreaks.com/topic/206442-blank-fields/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 1, 2010 Share Posted July 1, 2010 You would need to validate each submitted field (you should be validating anyway) and any fields that are empty should either be omitted from the UPDATE query or you could use the same field name on the right-hand side of the = so that the field will be updated with its current value. For example - UPDATE your_table SET column_name1 = column_name1, other columns here... instead of - UPDATE your_table SET column_name1 = 'value form the form', other columns here... Quote Link to comment https://forums.phpfreaks.com/topic/206442-blank-fields/#findComment-1079916 Share on other sites More sharing options...
rwwd Posted July 1, 2010 Share Posted July 1, 2010 Hi there sounds to me like you need some error checking in place to see if all the elements passed from the form to the processing script are set, and if they are not, flag an error or just redirect to original form, I'm guessing then, that you are performing no sanitizing checks before the info is entered into the DB Rw Quote Link to comment https://forums.phpfreaks.com/topic/206442-blank-fields/#findComment-1079952 Share on other sites More sharing options...
Snaggle Posted July 1, 2010 Author Share Posted July 1, 2010 That's right i'm not. I'm pretty new to PHP and this is my first go at a user system and it never crossed my mind leaving blanks would erase data. Quote Link to comment https://forums.phpfreaks.com/topic/206442-blank-fields/#findComment-1079962 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.