Omzy Posted July 12, 2010 Share Posted July 12, 2010 I have a form with some input fields; all fields are disabled by default, so this means those fields do not get posted unless a tickbox is ticked to enable them. Also in the form is a hidden field "userid". I want to check if "userid" is the ONLY field in the $_POST array - if yes then I can just redisplay the form. Quote Link to comment https://forums.phpfreaks.com/topic/207544-check-if-a-post-variable-is-the-only-one-in-_post/ Share on other sites More sharing options...
Pikachu2000 Posted July 12, 2010 Share Posted July 12, 2010 Why not just check for the value of the checkbox? If it's unset, and userid is set, then proceed to redisplay the form. Quote Link to comment https://forums.phpfreaks.com/topic/207544-check-if-a-post-variable-is-the-only-one-in-_post/#findComment-1085107 Share on other sites More sharing options...
Omzy Posted July 12, 2010 Author Share Posted July 12, 2010 Sorry I should have been more clear - there is one checkbox per field (5 fields in total). Quote Link to comment https://forums.phpfreaks.com/topic/207544-check-if-a-post-variable-is-the-only-one-in-_post/#findComment-1085108 Share on other sites More sharing options...
Pikachu2000 Posted July 12, 2010 Share Posted July 12, 2010 Ah, yes. Well then that changes up the method of attack slightly. Set them up as an array, then if the array is empty, and userid is not empty, you can proceed to redisplay the form. If I might ask, what's the purpose of checking a checkbox, then submitting the form? What happens then? Just wondering if there might be an easier way to accomplish the same thing. Quote Link to comment https://forums.phpfreaks.com/topic/207544-check-if-a-post-variable-is-the-only-one-in-_post/#findComment-1085120 Share on other sites More sharing options...
Omzy Posted July 13, 2010 Author Share Posted July 13, 2010 Basically I construct the SQL query based on what fields need updating. If the user only needs to update one field then there isn't much sense in overwriting all the other fields with the same data. Unless you know of a more elegant way to achieve the same behaviour? Quote Link to comment https://forums.phpfreaks.com/topic/207544-check-if-a-post-variable-is-the-only-one-in-_post/#findComment-1085124 Share on other sites More sharing options...
jcbones Posted July 13, 2010 Share Posted July 13, 2010 If you submit the same information to MySQL, it will not overwrite that column. It will only overwrite columns that are not the same. IIRC. MySQL Update Syntax Single-table UPDATE assignments are generally evaluated from left to right. For multiple-table updates, there is no guarantee that assignments are carried out in any particular order. If you set a column to the value it currently has, MySQL notices this and does not update it. Quote Link to comment https://forums.phpfreaks.com/topic/207544-check-if-a-post-variable-is-the-only-one-in-_post/#findComment-1085133 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.