开发者

textfield value changing detect in php

 <input name="aa" type="text" id="aa" value="please enter your name" size="22"            maxlength="60" />
 <input name="aab" type="text" id="aab" value="please enter your email" size="22"            maxlength="60" />

i have a textfield and it's value is "please enter your name"(likewise i have many fields.i want t开发者_运维技巧o add the value to the database only if the value is changed.(if user entered a name)

i used php isset function and it does not work properly. how to detect that in php?


You should do this on the frontend with a ready-made validation library, e.g. in jQuery or Prototype. Clearly you also need some validation on the backend, however 'garbage in, garbage out' applies and you should tidy your input data before it gets anywhere near you PHP code.


If you have an array with previous values you can easily compare all field values against the previous ones you had, and if any of them are different, then update.

UPDATE: Sorry didn't understand your question at first. As it was mantioned in other answer you better check it in front end and obly after work it through you php code.


You should do the comparison after the form is posted by fetching the data from the database and inserting new records as necessary. You also should use transactions to be sure of race conditions. If it is a critical system you have to perform extensive tests.


isset() probably works as it should but it will only return false if variable doesn't exist or is null.
If I understand the problem correctly you should do something like:

if($_POST["aa"]!="please enter your name" && isset($_POST["aa"])){
    //do something
}

same is true for other field:

if($_POST["aab"]!="please enter your email" && isset($_POST["aab"])){
    //do something
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜