6 Replies - 9058 Views - Last Post: 21 March 2010 - 04:50 PM Rate Topic: -----

#1 peter433  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 11
  • Joined: 09-February 10

Printing a PHP Variable in a Text Box

Posted 20 March 2010 - 04:21 PM

Hello, I know this is an old topic but It relates to my problem so thought Id reply.

I'm executing HTML code from PHP & need to insert a PHP variable into the text box value="". But I have tried countless attempts to make this succeed but to no avail.

I think the problem is because the HTML is being called by the PHP ? I have included code below, this runs in a loop.

 echo '<input name="rowID" type="textbox" id="rowID" value="" />'; 


The variable I would like in the value="" area is $rowID but I have tried various combinations of brackets, full stops, escaping characters etc but just cannot get this to work.

Any help would be greatly appreciated.

Is This A Good Question/Topic? -1
  • +

Replies To: Printing a PHP Variable in a Text Box

#2 Aurel300  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 230
  • Joined: 10-November 07

Re: Printing a PHP Variable in a Text Box

Posted 21 March 2010 - 05:02 AM

Lol...
<input name="rowID" type="textbox" value="<?php echo $rowID; ?>" />


Is it that hard? Also, I think THAT is not such a big problem in readability!
Was This Post Helpful? -1
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,659
  • Joined: 23-August 08

Re: Printing a PHP Variable in a Text Box

Posted 21 March 2010 - 08:51 AM

Split from necro'd topic.

People come to PHP without putting any thought into and/or trying to understand what's going on underneath it all.

Steps (somewhat simplified) in a request to a PHP Page:

1. Web browser makes request to page which the web server recognizes as a request to a PHP page
2. PHP processes the request, outputting HTML (to web server)
3. Web server sends HTML to web browser
4. Web browser renders HTML on client system
Was This Post Helpful? 0
  • +
  • -

#4 peter433  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 11
  • Joined: 09-February 10

Re: Printing a PHP Variable in a Text Box

Posted 21 March 2010 - 11:44 AM

I'm sorry if I came across as a noob but there is no need to insult my question. I did say I had been trying for quite some time with it, and that the reason I was having trouble is because the HTML is getting written by the PHP.

The reply stated above does not work and only prints - <?php echo $rowID; ?> as opposed to the row id number.

I had previously tried this and many other variations to get it working but with no success.
Was This Post Helpful? -1
  • +
  • -

#5 Aurel300  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 230
  • Joined: 10-November 07

Re: Printing a PHP Variable in a Text Box

Posted 21 March 2010 - 01:56 PM

I did not insult you - I mean, if it does not work, it is either because the PHP is not working, or because you are already in an echo statement.
If so, it is:
<?php
echo '<input name="rowID" type="textbox" value="'.$rowID.'" />';
?>


Was This Post Helpful? 1
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,659
  • Joined: 23-August 08

Re: Printing a PHP Variable in a Text Box

Posted 21 March 2010 - 02:29 PM

If what you're getting printed is literally this:
<?php echo $rowID; ?>

then your web server/PHP setup is wrong.

What is the extension on the file? Is it .html? If so, that would explain it; to a web server an .html file is nothing more than a text file on the disk it is to read and send exactly as it appears.

If the extension is .php, then the web server -- if setup properly -- should see that, say "OH, this is a PHP file, I need to send this file through to the PHP processor for handling before I send it to the browser" and will do that. The PHP processor will read the file and just spit it out to the web server until it comes across a <?php tag, at which point it will say, "OK, I need to send the web server the current value of the variable $rowID here," and then when it hits the ending ?> tag, it will go back to sending the raw HTML to the web server until the end of the file.

But, you've given us VERY LITTLE information on which to go, so diagnosing further is a bit difficult.
Was This Post Helpful? 0
  • +
  • -

#7 peter433  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 11
  • Joined: 09-February 10

Re: Printing a PHP Variable in a Text Box

Posted 21 March 2010 - 04:50 PM

Hello again, I did post more code but one of the above comments helped. Thanks very much :)

Also sorry for being vague.

This post has been edited by peter433: 21 March 2010 - 04:53 PM

Was This Post Helpful? -1
  • +
  • -

Page 1 of 1