Re: Using multiple submits on a page and retaining $POST data
| From: | Onochie Anyanetu | Date: | Fri, 16 Mar 2007 19:08:03 +0000 |
| Subject: | Re: Using multiple submits on a page and retaining $POST data | ||
| References: | 1 2 3 4 5 6 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-43294@lists.php.net to get a copy of this message | ||
solved.
Thanks Dan, this was pretty much the solution I came up with. Thank you
Gunawan for the idea that got the ball rolling as well
Onochie
On 3/16/07, Dan Shirah <mrsquash2@gmail.com> wrote:
Try something like this: ****Your query here to get your dropdown values**** ** *// This first option value will set your default dropdown to display as blank* echo "<OPTION value=\"\">--SELECT--</OPTION>\n"; *// This will create a loop to return each option of your dropdown* foreach ($query_result as $q) { *// This if statement says that IF the value in your database matches your $_POST(selected) value then mark it as SELECTED*if ($q['my_column_value'] == $_POST['my_selected_value']) echo "<OPTION value=\"{$q['my_column_value']}\"SELECTED>{$q['my_column_value']}</OPTION>\n"; *// This else statement will return your default(unselected) dropdown list if it can't match the selected value with a value in your database*else echo "<OPTIONvalue=\"{$q['my_column_value']}\">{$q['my_column_value']}</OPTION>\n"; } Hope that helps. On 3/16/07, Onochie Anyanetu <ubernoch@gmail.com> wrote: Almost what I wanted to do. I am looking for a way to set the default option value to the selection the user just chose. for example, something like <select name=cars value=$_POST['cars']> On 3/16/07, Gunawan Wibisono <landavia81@gmail.com> wrote:solved On 3/16/07, Onochie Anyanetu <ubernoch@gmail.com> wrote:youHello Gunawan On your first comment, im not sure what you were referring to whensaiddatait is a js problem on your second comment, i am talking about the user entered data.meanssubmitted by the first submit button will always be predefined byofisthe user using a selection box, the data im concerned with checkingthelike:input boxes he will be seeing. and this wont necessarily beusername/pass.and im trying to do this in php if at all possible. on your next comment, (6) i am talking about after i vertified thevalidityof the user typed/entered data, i will enter that into my db next comment - i knew this would be hard to describe, but i'll tryagain.this is to be done all on one page. and ive tried using somethingselectedvalue=\"$_POST['name']\"but i am having problems keeping the initial drop down at thegoes tochoice, so whenever either submit button is pressed and the postphpisself, the drop down is refreshed back to its starting value, whichNULL hahaha.. that's simple.. drop down menu always return to the null because u don't give selected on one of option. i have a function (build in) that's answer your problem.. if you on hurry.. i'm sory, i cant give it now.. my skrip in other comp.. <select> <option value="base" selected>sale options</option> <option value="base2" >Buy options</option> </select> try this on offline i believe.. the first you enter the page.. the sale option will be selected now add 2 option then try one of the option you add have selected.. what happen next you will see the default will be change, remember erase selected forgive me.. i think it matter of js but it matter of html. fyi.. try using ajax .. i believe it make your life for comfort.. (since it don't need to refresh the page) and make your skill up.meI hope that helps define my problem a little more Onochie On 3/16/07, Gunawan Wibisono <landavia81@gmail.com > wrote:that's not php problem that's was javascript problem On 3/16/07, Onochie Anyanetu < ubernoch@gmail.com> wrote:Hello, and I would like to thank everyone that attempts to helpout.andIhave looked long and hard online before I resorted to this. My problem is that I have a page that relies on multiple submitsdataenteredfrom what was submitted. example: // 1. some sort of drop down // 2. submit button // 3. display data retrieved from database // 4. user enters more information // 5. second submit button, run checks to vertify all data isu mean when clicked.. the info like username are check whenever isandvalid or not?? perhaps u should try ajax// 6. enter data into databasei don't get it what u mean in here??The problem is in step 5, when the user hits the second submitdatatheischecked before db submission, I am losing the data displayed bypage ufirstsubmit buttonhmm i don't get it by reading at the first. i think in the 2ndbutshould try to make <input type=hidden name=user value=landa> this input contain what previous data enter... foreach($_POST as $nm=>$val){ $txt.="<input type=hidden name=$nm value=$val>"; } echo $txt;This is what I have tried ive tried using POST and SESSION variables to display the data,thisstatementdoesnt work. this is because in my code i have an if issettoretrievedcheck if submit has been pressed, then the variables arefromarethedb and used. when clicking the second submit button and checksdone,submitthetop portion of the page of information retrieved by the firstare(usingnothing but blanks because the first submit is no longer setisset)my next idea was to save the variable selected in the first dropdownto(step1) and requery with this selection at the second submit buttonwasretrieveand redisplay the data. this did not work because this variablesetdisablingbackto "" because the drop down resets itself on each submit.thediddropdown if the first submit is set and then setting the variablenotis noworkeither because when the second submit is hit, the first submitand ilongerset, so the drop down is displayed, the variable is set to ""getglobalnothing in my variable. this also was the case if i made it aoutvariable.i wish to see the offline from your pages.. if able send to meso basically i have resorted to just googling things and tryingthedifferent arrangements of code to no avail. I need a way to holddata onmanipulated.the top half of the screen while the bottom half is beingany,Thankand i mean any help at this point would be GREATLY appreciated!you.-- akan ada dimana mulut terkunci dan suara tak ada lagi.. saat itu gunakanlah HP untuk melakukan SMS!! -> ini aliran bedul.. bukan aliran aneh. tertawa sebelum tertawa didepan RSJ..Onochie-- akan ada dimana mulut terkunci dan suara tak ada lagi.. saat itu gunakanlah HP untuk melakukan SMS!! -> ini aliran bedul.. bukan aliran aneh. tertawa sebelum tertawa didepan RSJ..