Jump to content

check if a post variable is the only one in $_POST


Omzy

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
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.