I am trying to write a dynamic form using PHP.
- The upper form, for a name, allows for the search of an element in the mysql database, for example
- In the database, this name is associated with
If I press the "Search" button on the upper form, then the bottom form is displayed and the text field is from the database related to this name. If I change the username to another value and then " Oj "presses me, then shown data about new records and so on.
The lower form also has a button "Update" which allows the changes made in the text box (in the lower part).
Now, I have the following problem: In my script, I initially set the value of the name (from upper form) to ". When I press the "Search" button, the lower part of the form is shown and related data is displayed in the lower part. When I press the "Update" button, the text field associated with the name is set to an empty string. The reason for this is that in my script I initially set the name "". I would like that in this case the data entered in the upper form does not change, i.e., it remains the same.
I think, I'm missing something here. Perhaps this is an easy solution for this and I'm doing something wrong in a fundamentally wrong way. If you can help me then it would be great.
That's what I tried ... I've removed a lot of details, but I think you can give me an idea which I am trying to do. Note that the entire code file is in update.php.
& lt ;? Php function search_bus ($ mysql, $ name) {// Some things are here ...} function update_bus ($ Mysql, $ b_id) {// Some goods are here ...} // Some global variables $ b_id = 0 ; $ Username = ""; // Business Username // b_id that matches the username (if isset ($ _ request ['search'])) {$ b_id = 0; // Business ID if (isset ($ _ POST ['user'])) {$ username = $ _POST ['user']; $ B_id = search_bus ($ mysql, $ username); }} Otherwise (isset ($ _ request ['update'])) {update_bus ($ mysql, $ b_id); }? & Gt; & Lt; H2 & gt; Search: & lt; / H2 & gt; & Lt; Name of the form = "search_bus" method = "post" action = "& lt ;? phcho echo $ _SERVER ['PHP_SELF'] ;; & gt; & Gt; Username: & lt; Input type = "text" name = "user" value = "& lt;? = Htmlentities ($ user name)? & Gt;" /> & Lt; Input type = "submit" value = "Suchen" name = "search" /> & Lt; / Form & gt; & Lt ;? Php if ($ b_id! = 0) {? & Gt; & Lt; H2 & gt; Data: & lt; / H2 & gt; & Lt; Form name = "business_design" method = "post" action = "& lt ;? Php echo $ _SERVER ['PHP_SELF'] ;;>" & Gt; & Lt; - Some form here - & gt; & Lt ;? Php}? & Gt;
I think that what you remember is one to maintain it Creating the HTML hidden field is the value of the name variable.
& lt; Input type = "hidden" name = "name" value = "& lt ;? php print $ namever?" / & Gt;
Add this input to both forms so that you can keep the price, no users click on the user.
Hope this will be helpful.
& lt; H2 & gt; Search: & lt; / H2 & gt; & Lt; Name of the form = "search_bus" method = "post" action = "& lt ;? phcho echo $ _SERVER ['PHP_SELF'] ;; & gt; & Gt; Username: & lt; Input type = "text" name = "user" value = "& lt;? = Htmlentities ($ user name)? & Gt;" /> & Lt; Input type = "hidden" name = "b_id" value = "& lt ;? php print $ b_id?" / & Gt; & Lt; Input type = "submit" value = "Suchen" name = "search" /> & Lt; / Form & gt; & Lt ;? Php if ($ b_id! = 0) {? & Gt; & Lt; H2 & gt; Data: & lt; / H2 & gt; & Lt; Form name = "business_design" method = "post" action = "& lt ;? php echo $ _SERVER ['PHP_SELF'];>" Gt; & Lt; Input type = "hidden" name = "b_id" value = "& lt ;? php print $ b_id?" / & Gt; & Lt; - Some form here - & gt; & Lt ;? Php}? & Gt; Do not start $ B_id if it already comes in http request. If (! Isset ($ _ POST ['b_id'])) {$ b_id = 0; } And {$ b_id = $ _POST ['b_id']; }
In this way you can remember the last selected value of b_id. Hope this can help you.
Comments
Post a Comment