3 Replies - 51189 Views - Last Post: 18 December 2008 - 03:35 AM Rate Topic: -----

#1 rpjd  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 88
  • Joined: 08-March 07

Assigning PHP variable to a html text box

Posted 08 March 2007 - 07:43 AM

I am using php to query a postgresql database and assigning the resultant variable to a html form/text field. I am new to php, but have not found anything that describes how this is achieved. I have tried in vain using a combination of php and javascript, without success. Any help/insight appeciated :) It's probably simple, but to a beginner!

 <input type="text" name="something" value="$php-variable-goes-here"/>



RPJD

Is This A Good Question/Topic? 1

Replies To: Assigning PHP variable to a html text box

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Assigning PHP variable to a html text box

Posted 08 March 2007 - 09:03 AM

You'll need to escape the html into php to display the variable. Something like:
<input type="text" name="something" value="<?=$php-variable-goes-here?>"/>


Was This Post Helpful? 1

#3 sandesh_k  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-December 08

Re: Assigning PHP variable to a html text box

Posted 18 December 2008 - 12:52 AM

View Postrpjd, on 8 Mar, 2007 - 06:43 AM, said:

I am using php to query a postgresql database and assigning the resultant variable to a html form/text field. I am new to php, but have not found anything that describes how this is achieved. I have tried in vain using a combination of php and javascript, without success. Any help/insight appeciated :) It's probably simple, but to a beginner!

[code] <input type="text" name="something" value="$php-variable-goes-here"/>[code]


RPJD


try this ,


<input type="text" name="something" value="<?php echo $php-variable-goes-here"/>

:^:
Was This Post Helpful? 0
  • +
  • -

#4 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 543
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: Assigning PHP variable to a html text box

Posted 18 December 2008 - 03:35 AM

Or, for cleaner code:

<?php

echo "<input type='text' name='something' value='{$phpvar}'>";

?>



For readability, it is recommended not to write a big block of HTML with frequent breaks in and out of PHP for variable echoing.
Was This Post Helpful? 1

Page 1 of 1