View Full Version : Posting a Variable into a text box

02-25-2008, 04:18 PM
Hello all

I have a query about posting a variable into a text box. Mainly to see if anyone has any good references or can give me some instructions. I'm a fairly newcomer to PHP so any help is appreciated.

I have a form and a list of items that can be used to fill out the form and then submit to a database. I would like to make the list of items into a list of hyperlinks, so that when I click on one of these the item will get added to the text box in my form.

I have the value as a variable, as they are pulled from a database, so how can I post this back to the page and then into the textbox...

Anyone with ideas?

Form to add to:

<form action = "entered_data1.php" method = "post"
enctype = "multipart/form-data" name="form01">
<table width="95&#37;" border="0" cellspacing="0" cellpadding="3">
<td><p class="subHeader">ID</p></td>
<td><input name="product_id" type="text" value=" " size="30" maxlength="30" /></td>

Written to page as so:

<?php echo "<a href='#'>" .$titlehigh. "</a>" ?><br>

Anything else?


Andrew Johnson
02-25-2008, 04:48 PM
I'm confused but if you want the variable $titlehigh in a textbox try this:

<input type="text" name="textbox_name" value="<?php echo $titlehigh; ?>" />

02-26-2008, 10:56 AM
Sorry for the confusion, I'm always doing this :rolleyes:.

I think that is fine, I was just wondering that if I use the line

<?php echo "<a href='#'>" .$titlehigh. "</a>" ?><br>

in a loop of some sort to print multiple of the $titlehigh variables (where the value in $titlehigh changes each time), and then to select one out of the five or so that are printed on the page. I forgot to mention that didn't I..

If I did what you suggested wouldn't it automatically print whichever value $titlehigh has landed on when the page loads?