Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi All, How can I assign the val

Status
Not open for further replies.

Bastien

Programmer
May 29, 2000
1,683
CA
Hi All,

How can I assign the value from a DB query to a textbox
I would have thought it would be something like:

$myValue = $row["DBValue"];

and then on the form

<input type = text name = myValue value = $myValue>

The form is created by a function which is used in other places as well so, sometimes it needs to be blank (when I wish to add something to the DB) and other times it needs the value from the DB.

TIA

Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
myvalue is filled with the result of the db, that is correct, if there is no result it will be blank.

But writing funtions that are dependend on many kinds of different variables is not very handy. Try building more functions altough they look similar, in the future the script will be more reusable for u.

If the above didnt answer the question please post more about the funtion. mcvdmvs
-- &quot;It never hurts to help&quot; -- Eek the Cat
 
If this is PHP
try
<input type=&quot;text&quot; name =&quot;myValue&quot; value =&quot;<php echo $myValue ?>&quot;>
 
Hi All

The correct answer is to add some code along with the GLOBAL keyword to identify the variables as not being local inside the function.

thanks for the advice

Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
$myVal = $row['DBValue'];
print &quot;<input type=\&quot;text\&quot; name=\&quot;field\&quot; value=\&quot;$myVal\&quot;>&quot;;
//
// if textarea
//
print &quot;<textarea name=\&quot;myfield\&quot;>$myVal</textarea>&quot;;
 
Salinasj

Your code will only work if the variables are both in the same function or both not in a function at all. If you create a function to do whatever and you need to use a variable from outside the function, using the same variable name will createa new local variable and will not have the same results. The GLOBAL keyword will allow the varaible inside and outside the function to have the same value.

hth
Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
that is correct.
if you are wanting to call it as a function, you would definitely have to specify the GLOBALs or specify the parameters to use & make sure they are returned properly.
(sorry, didn't see he was wanting to use it as a function.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top