Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/206442-blank-fields/
Share on other sites

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...

Link to comment
https://forums.phpfreaks.com/topic/206442-blank-fields/#findComment-1079916
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/206442-blank-fields/#findComment-1079952
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.