getting previously stored data in form before submitting

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chris_s_22
Forum Commoner
Posts: 76
Joined: Wed Dec 31, 2008 2:05 pm

getting previously stored data in form before submitting

Post by chris_s_22 »

How do i get previous stored data from the database and display it in the feild

As you can see i can do it for text boxes and textarea

Code: Select all

 
Feild1:<input type="text" size="20" maxlength="20" name="feild1" value="<?php echo $feild1?>" align="" tabindex=""><br>
 
Feild2:<textarea name="feild2" cols="20" rows="5" tabindex=""><?php echo $feild2?></textarea><br>
 
but how would i do it for a drop down menu

Code: Select all

Feild3:
<select name="feild3">
<option value="1">option1</option>
<option value="2">option2</option>
</select>
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: getting previously stored data in form before submitting

Post by McInfo »

It's much the same, except that the values are stored in an array and the <option>s are written in a loop (while, do-while, for, foreach).

Please use .

Edit: This post was recovered from search engine cache.
Last edited by McInfo on Thu Jun 17, 2010 2:58 pm, edited 1 time in total.
chris_s_22
Forum Commoner
Posts: 76
Joined: Wed Dec 31, 2008 2:05 pm

Re: getting previously stored data in form before submitting

Post by chris_s_22 »

im still a bit confused any chance you could do a demonstration

like how it would work in this situation.say i already queried the data base and put result in
$sex

<select name="sex">
<option value="1">male</option>
<option value="2">female</option>
</select>
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: getting previously stored data in form before submitting

Post by McInfo »

I could, but I'm not sure that would help. I proposed tags and that didn't help.

I'm sure you can figure it out if you spend a few more minutes reading through the examples in the manual.

Make a test script with a hard-coded array and write a loop to iterate through the array. I will help if you have trouble, but I need see some effort from you first.

Edit: This post was recovered from search engine cache.
Last edited by McInfo on Thu Jun 17, 2010 2:59 pm, edited 1 time in total.
chris_s_22
Forum Commoner
Posts: 76
Joined: Wed Dec 31, 2008 2:05 pm

Re: getting previously stored data in form before submitting

Post by chris_s_22 »

Im sorry really dont understand what you mean by

Code: Select all

 
could you point me in direction of a turtorial that explains the logic and covers this

i know how to select a feild and i know how to get data and display it like so

Code: Select all

Feild3:
<OPTION selected value="<?php echo $feild3?>"><?php echo $feild3?></OPTION>
<select name="feild3">
<option value="1">option1</option>
<option value="2">option2</option>
</select>
However this method would mean that when the user came to change it, the data from database would display preselected at top but would also appear again in the list.

a work arround this would just to put a extra 1 or 2 feilds like so

Code: Select all

 
<option value="0"></option>
<option value="0">----------</option>
 
not exactly what i wanted but my best solution so far
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: getting previously stored data in form before submitting

Post by McInfo »

You need to query the database and retrieve a list of values and labels that will fill the <option>s in the <select>. While looping through the rows, compare the current row value to the user-selected value. If they match, give the <option> a selected="selected" attribute.

Related topic: (broken) 103335
chris_s_22 wrote:Im sorry really dont understand what you mean by
If you read your post after posting it, you might have noticed that was converted into a code box. The difference between that code box and one created with plain tags is that the HTML code box syntax-highlights HTML within it.

Plain BBCode code tags:

Code: Select all

<select name="feild3">
<option value="1">option1</option>
<option value="2">option2</option>
</select>
HTML BBCode code tags:

Code: Select all

<select name="feild3">
<option value="1">option1</option>
<option value="2">option2</option>
</select>
Edit: This post was recovered from search engine cache.
Post Reply