By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,827 Members | 2,155 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,827 IT Pros & Developers. It's quick & easy.

displaying data to form....

P: n/a
dba
Have been displaying data from database using html for some time but
just recently trying to display data back to "form". Can't find answer.

<form method="post" action="<?php echo $PHP_SELF;?>">
First Name:<input type="text" size="12" maxlength="12" name="Fname"><br >
Last Name:<input type="text" size="12" maxlength="36" name="Lname"><br />
Gender:<br />
Male:<input type="radio" value="Male" name="gender"><br />
Female:<input type="radio" value="Female" name="gender"><br />

Now once I have the data in the database I want to display in the same
form. Have been doing googles and have for some time been displaying
using html like

echo "Hello, ".$Fname." ".$Lname.".<br />";
echo "You are ".$gender.", and you like ";

but just lately realized I have never display in a "form".

Any help will be appreciated.
Jun 2 '08 #1
Share this Question
Share on Google+
11 Replies


P: n/a
dba wrote:
Have been displaying data from database using html for some time but
just recently trying to display data back to "form". Can't find answer.

<form method="post" action="<?php echo $PHP_SELF;?>">
First Name:<input type="text" size="12" maxlength="12" name="Fname"><br >
Last Name:<input type="text" size="12" maxlength="36" name="Lname"><br />
Gender:<br />
Male:<input type="radio" value="Male" name="gender"><br />
Female:<input type="radio" value="Female" name="gender"><br />

Now once I have the data in the database I want to display in the same
form. Have been doing googles and have for some time been displaying
using html like

echo "Hello, ".$Fname." ".$Lname.".<br />";
echo "You are ".$gender.", and you like ";

but just lately realized I have never display in a "form".

Any help will be appreciated.
You need alt.html to find out how html works.

Hint - the input field has a "value" attribute which contains the test
you wish to display in it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 2 '08 #2

P: n/a
On May 6, 7:44 pm, dba <some...@someplace.orgwrote:
Have been displaying data from database using html for some time but
just recently trying to display data back to "form". Can't find answer.

<form method="post" action="<?php echo $PHP_SELF;?>">
First Name:<input type="text" size="12" maxlength="12" name="Fname"><br >
Last Name:<input type="text" size="12" maxlength="36" name="Lname"><br />
Gender:<br />
Male:<input type="radio" value="Male" name="gender"><br />
Female:<input type="radio" value="Female" name="gender"><br />

Now once I have the data in the database I want to display in the same
form. Have been doing googles and have for some time been displaying
using html like

echo "Hello, ".$Fname." ".$Lname.".<br />";
echo "You are ".$gender.", and you like ";

but just lately realized I have never display in a "form".

Any help will be appreciated.
Okay, I think I know what you are trying to do. You want to retrieve
data from a db to populate entry options on a form that was initially
used to enter the information. Here's sample code from one of my
scripts to give you a good example on how to do this. This is for the
select/options html element. You will have to do it differently for
text areas, radio boxes, and others. But this snippet should get you
on the right track:
//run the query to get all data stored in the INTAKE 1 FORM for this
id

$query = "select * from intake1 where consumer_id = ".$id;
$result = mysql_query($query);
if($row = mysql_fetch_array($result)) {

//there are many fields, but we are just using this one
//for demonstration purposes

$gender_form_entry = $row["gender_id"];
}
later on down the page i have this code for the gender section on the
form
<form>
....
<td>
<div class="formUnitVertical">
<label for="gender">Gender:</label>
<br/>
<select name="gender">
<?php

//get data entered in the gender table
$genderQuery = "select * from lst_gender";
$result = mysql_query($genderQuery);

//take resultset and makeform vars
while($row=mysql_fetch_array($result)) {

$gender_id = $row["id"];
$gender_type = $row["gender"];

//see if there is a gender id stored for
this form
//associated with this consumer id
if($gender_form_entry == $gender_id){

//yes, there is an id stored for this
form that matches
//an id from the gender table, so mark
it as SELECTED
echo "<option value=\"".$gender_id."\"
selected>".$gender_type."</option>";

}else{

//nothing stored in database, select
nothing
echo "<option value=\"".$gender_id."\">".
$gender_type."</option>";

}
}
?>
</select>
</div>
</td>
....
<input type='submit' />
...
</form>
hope this helps

chris
Jun 2 '08 #3

P: n/a
On May 7, 1:44 am, dba <some...@someplace.orgwrote:
Have been displaying data from database using html for some time but
just recently trying to display data back to "form". Can't find answer.

<form method="post" action="<?php echo $PHP_SELF;?>">
First Name:<input type="text" size="12" maxlength="12" name="Fname"><br >
Last Name:<input type="text" size="12" maxlength="36" name="Lname"><br />
Gender:<br />
Male:<input type="radio" value="Male" name="gender"><br />
Female:<input type="radio" value="Female" name="gender"><br />

Now once I have the data in the database I want to display in the same
form. Have been doing googles and have for some time been displaying
using html like

echo "Hello, ".$Fname." ".$Lname.".<br />";
echo "You are ".$gender.", and you like ";

but just lately realized I have never display in a "form".

Any help will be appreciated.
<input type="text" name="inputFieldName" value="<?php echo
($thisFieldValue); ?>" />

If the data contains characters that have special meaning in HTML such
as < & etc then use htmlspecialchars () to escape them.

Textareas simply require you to do the echo between the <textareaand
</textareatag.

Now you know how to do inputs and textareas I'll leave selects,
checkboxes and radio buttons as an exercise for the original poster.
Hint: Select options have a "selected" attribute, checkboxes and
radios have a "checked" attribute.
Jun 2 '08 #4

P: n/a
dba
Really?

<input type="text" name="inputFieldName" value="<?php echo
($thisFieldValue); ?>" />

Jerry Stuckle wrote:
dba wrote:
>Have been displaying data from database using html for some time but
just recently trying to display data back to "form". Can't find answer.

<form method="post" action="<?php echo $PHP_SELF;?>">
First Name:<input type="text" size="12" maxlength="12" name="Fname"><br >
Last Name:<input type="text" size="12" maxlength="36" name="Lname"><br />
Gender:<br />
Male:<input type="radio" value="Male" name="gender"><br />
Female:<input type="radio" value="Female" name="gender"><br />

Now once I have the data in the database I want to display in the same
form. Have been doing googles and have for some time been displaying
using html like

echo "Hello, ".$Fname." ".$Lname.".<br />";
echo "You are ".$gender.", and you like ";

but just lately realized I have never display in a "form".

Any help will be appreciated.

You need alt.html to find out how html works.

Hint - the input field has a "value" attribute which contains the test
you wish to display in it.
Jun 2 '08 #5

P: n/a
dba
Thanks so much Chrisv and Gordon. That jogged my memory. I appreciate
the help.

Gordon wrote:
On May 7, 1:44 am, dba <some...@someplace.orgwrote:
>Have been displaying data from database using html for some time but
just recently trying to display data back to "form". Can't find answer.

<form method="post" action="<?php echo $PHP_SELF;?>">
First Name:<input type="text" size="12" maxlength="12" name="Fname"><br >
Last Name:<input type="text" size="12" maxlength="36" name="Lname"><br />
Gender:<br />
Male:<input type="radio" value="Male" name="gender"><br />
Female:<input type="radio" value="Female" name="gender"><br />

Now once I have the data in the database I want to display in the same
form. Have been doing googles and have for some time been displaying
using html like

echo "Hello, ".$Fname." ".$Lname.".<br />";
echo "You are ".$gender.", and you like ";

but just lately realized I have never display in a "form".

Any help will be appreciated.

<input type="text" name="inputFieldName" value="<?php echo
($thisFieldValue); ?>" />

If the data contains characters that have special meaning in HTML such
as < & etc then use htmlspecialchars () to escape them.

Textareas simply require you to do the echo between the <textareaand
</textareatag.

Now you know how to do inputs and textareas I'll leave selects,
checkboxes and radio buttons as an exercise for the original poster.
Hint: Select options have a "selected" attribute, checkboxes and
radios have a "checked" attribute.
Jun 2 '08 #6

P: n/a
dba
chrisv,

Jogged my memory and then a lot more. Thanks again.

chrisv wrote:
On May 6, 7:44 pm, dba <some...@someplace.orgwrote:
>Have been displaying data from database using html for some time but
just recently trying to display data back to "form". Can't find answer.

<form method="post" action="<?php echo $PHP_SELF;?>">
First Name:<input type="text" size="12" maxlength="12" name="Fname"><br >
Last Name:<input type="text" size="12" maxlength="36" name="Lname"><br />
Gender:<br />
Male:<input type="radio" value="Male" name="gender"><br />
Female:<input type="radio" value="Female" name="gender"><br />

Now once I have the data in the database I want to display in the same
form. Have been doing googles and have for some time been displaying
using html like

echo "Hello, ".$Fname." ".$Lname.".<br />";
echo "You are ".$gender.", and you like ";

but just lately realized I have never display in a "form".

Any help will be appreciated.

Okay, I think I know what you are trying to do. You want to retrieve
data from a db to populate entry options on a form that was initially
used to enter the information. Here's sample code from one of my
scripts to give you a good example on how to do this. This is for the
select/options html element. You will have to do it differently for
text areas, radio boxes, and others. But this snippet should get you
on the right track:
//run the query to get all data stored in the INTAKE 1 FORM for this
id

$query = "select * from intake1 where consumer_id = ".$id;
$result = mysql_query($query);
if($row = mysql_fetch_array($result)) {

//there are many fields, but we are just using this one
//for demonstration purposes

$gender_form_entry = $row["gender_id"];
}
later on down the page i have this code for the gender section on the
form
<form>
...
<td>
<div class="formUnitVertical">
<label for="gender">Gender:</label>
<br/>
<select name="gender">
<?php

//get data entered in the gender table
$genderQuery = "select * from lst_gender";
$result = mysql_query($genderQuery);

//take resultset and makeform vars
while($row=mysql_fetch_array($result)) {

$gender_id = $row["id"];
$gender_type = $row["gender"];

//see if there is a gender id stored for
this form
//associated with this consumer id
if($gender_form_entry == $gender_id){

//yes, there is an id stored for this
form that matches
//an id from the gender table, so mark
it as SELECTED
echo "<option value=\"".$gender_id."\"
selected>".$gender_type."</option>";

}else{

//nothing stored in database, select
nothing
echo "<option value=\"".$gender_id."\">".
$gender_type."</option>";

}
}
?>
</select>
</div>
</td>
...
<input type='submit' />
..
</form>
hope this helps

chris

Jun 2 '08 #7

P: n/a
dba wrote:
Really?

<input type="text" name="inputFieldName" value="<?php echo
($thisFieldValue); ?>" />

Jerry Stuckle wrote:
>dba wrote:
>>Have been displaying data from database using html for some time but
just recently trying to display data back to "form". Can't find answer.

<form method="post" action="<?php echo $PHP_SELF;?>">
First Name:<input type="text" size="12" maxlength="12"
name="Fname"><br >
Last Name:<input type="text" size="12" maxlength="36"
name="Lname"><br />
Gender:<br />
Male:<input type="radio" value="Male" name="gender"><br />
Female:<input type="radio" value="Female" name="gender"><br />

Now once I have the data in the database I want to display in the
same form. Have been doing googles and have for some time been
displaying using html like

echo "Hello, ".$Fname." ".$Lname.".<br />";
echo "You are ".$gender.", and you like ";

but just lately realized I have never display in a "form".

Any help will be appreciated.

You need alt.html to find out how html works.

Hint - the input field has a "value" attribute which contains the test
you wish to display in it.
Yes. "value" is an html attribute, not PHP code. Learn the difference.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 2 '08 #8

P: n/a
dba wrote:
Jerry Stuckle wrote:
>dba wrote:
>>Have been displaying data from database using html for some time but
just recently trying to display data back to "form". Can't find answer.

<form method="post" action="<?php echo $PHP_SELF;?>">
First Name:<input type="text" size="12" maxlength="12"
name="Fname"><br >
Last Name:<input type="text" size="12" maxlength="36"
name="Lname"><br />
Gender:<br />
Male:<input type="radio" value="Male" name="gender"><br />
Female:<input type="radio" value="Female" name="gender"><br />

Now once I have the data in the database I want to display in the
same form. Have been doing googles and have for some time been
displaying using html like

echo "Hello, ".$Fname." ".$Lname.".<br />";
echo "You are ".$gender.", and you like ";

but just lately realized I have never display in a "form".

Any help will be appreciated.

You need alt.html to find out how html works.

Hint - the input field has a "value" attribute which contains the test
you wish to display in it.

Really?

<input type="text" name="inputFieldName" value="<?php echo
($thisFieldValue); ?>" />
Oh, and please don't top post. (Top posting fixed this time).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 2 '08 #9

P: n/a
dba
I understand retard. Perhaps you ought to find something else to do with
your time.

Also, we have gone over your "flat earth society" bottom post rant before.

NEVER
Jerry Stuckle wrote:
dba wrote:
>Really?

<input type="text" name="inputFieldName" value="<?php echo
($thisFieldValue); ?>" />

Jerry Stuckle wrote:
>>dba wrote:
Have been displaying data from database using html for some time but
just recently trying to display data back to "form". Can't find answer.

<form method="post" action="<?php echo $PHP_SELF;?>">
First Name:<input type="text" size="12" maxlength="12"
name="Fname"><br >
Last Name:<input type="text" size="12" maxlength="36"
name="Lname"><br />
Gender:<br />
Male:<input type="radio" value="Male" name="gender"><br />
Female:<input type="radio" value="Female" name="gender"><br />

Now once I have the data in the database I want to display in the
same form. Have been doing googles and have for some time been
displaying using html like

echo "Hello, ".$Fname." ".$Lname.".<br />";
echo "You are ".$gender.", and you like ";

but just lately realized I have never display in a "form".

Any help will be appreciated.
You need alt.html to find out how html works.

Hint - the input field has a "value" attribute which contains the
test you wish to display in it.

Yes. "value" is an html attribute, not PHP code. Learn the difference.
Jun 2 '08 #10

P: n/a
On Wed, 07 May 2008 16:53:35 +0200, dba <so*****@someplace.orgwrote:
I understand retard. Perhaps you ought to find something else to do with
your time.
Hmmmz, after he helped you?
Also, we have gone over your "flat earth society" bottom post rant
before.
Ah, so you do know you should bottom post allready?
1 & 1 = PLONK

Have a very pleasant life.
--
Rik Wasmus
Jun 2 '08 #11

P: n/a
dba
Thanks for the thoughtful gesture. It is truly appreciated.

Rik Wasmus wrote:
On Wed, 07 May 2008 16:53:35 +0200, dba <so*****@someplace.orgwrote:
>I understand retard. Perhaps you ought to find something else to do
with your time.

Hmmmz, after he helped you?
>Also, we have gone over your "flat earth society" bottom post rant
before.

Ah, so you do know you should bottom post allready?
1 & 1 = PLONK

Have a very pleasant life.
Jun 2 '08 #12

This discussion thread is closed

Replies have been disabled for this discussion.