Page 1 of 1

Set form value from PHP variable

Posted: Tue Apr 24, 2007 8:04 pm
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>';

Posted: Tue Apr 24, 2007 8:31 pm
by John Cartwright
Give this a read to understand how to output variables in strings

http://www.php.net/manual/en/function.echo.php

Posted: Tue Apr 24, 2007 10:22 pm
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

Posted: Wed Apr 25, 2007 1:13 am
by Mohit_Prog
Try this way :
$test = '123'; ( data from sql query )
then

print '<td><input name = \"pname\" value='.$test.'></td>';

Posted: Wed Apr 25, 2007 8:30 am
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

Posted: Wed Apr 25, 2007 8:46 am
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().

Posted: Wed Apr 25, 2007 9:03 am
by benchmarkman
Thanksa million. You all are PHP gods.