Set form value from PHP variable

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
benchmarkman
Forum Newbie
Posts: 6
Joined: Tue Apr 24, 2007 8:01 pm

Set form value from PHP variable

Post by benchmarkman »

I am trying to create a form with a text box and set the text box to a PHP variable that I got from an SQL Query. The problem is I'm not sure how to set the input value to the PHP variable. I have a sample of the code below and where PHP VARIABLE is I want to stick my variable. Any guidance is greatly appreciated.

Code: Select all

print '<td><input name = \"pname\" value= PHP VARIABLE></td>';
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Give this a read to understand how to output variables in strings

http://www.php.net/manual/en/function.echo.php
benchmarkman
Forum Newbie
Posts: 6
Joined: Tue Apr 24, 2007 8:01 pm

Post by benchmarkman »

Nope already looked at that thread. I don't see anything about setting form values with PHP variable. Can you give me more specific help. Thanks
Mohit_Prog
Forum Commoner
Posts: 26
Joined: Mon Apr 23, 2007 6:10 am

Post by Mohit_Prog »

Try this way :
$test = '123'; ( data from sql query )
then

print '<td><input name = \"pname\" value='.$test.'></td>';
benchmarkman
Forum Newbie
Posts: 6
Joined: Tue Apr 24, 2007 8:01 pm

Post by benchmarkman »

Thanks, worked perfectly.

Now I have one more question. One of my fields in the database has html in it. I am trying to print the html as text and not html code. Is there a way around this? Thanks
Zu
Forum Commoner
Posts: 33
Joined: Wed Dec 06, 2006 4:21 am

Post by Zu »

benchmarkman wrote:Thanks, worked perfectly.

Now I have one more question. One of my fields in the database has html in it. I am trying to print the html as text and not html code. Is there a way around this? Thanks
htmlentities().
benchmarkman
Forum Newbie
Posts: 6
Joined: Tue Apr 24, 2007 8:01 pm

Post by benchmarkman »

Thanksa million. You all are PHP gods.
Post Reply