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
Sheridan
Forum Newbie
Posts: 18 Joined: Sat May 31, 2008 1:50 pm
Post
by Sheridan » Sat May 31, 2008 2:13 pm
Hi:
I am a newcomer to PHP. I am trying to put the value in a PHP variable into the value of a form control. The code I have tried is:
***** PLEASE USE THE CODE AND PHP TAGS *****
Code: Select all
$row = mysql_fetch_row($result);
$str = $row[1];
$str .= ", ";
$str .= $row[2];
echo '<form action="testSendQueryData.php" method="get">';
echo '<br>';
echo '<input type="text" name="iName" value = $str>';
echo '<input type="submit">';
The code:
Code: Select all
"value = $str"
does not work. The form sends the string "$str". I have also tried:
echo '<input type="text" name="iName" value = value = <?php echo "$str;" ?>>
Anyone know a solution?
nowaydown1
Forum Contributor
Posts: 169 Joined: Sun Apr 27, 2008 1:22 am
Post
by nowaydown1 » Sat May 31, 2008 2:43 pm
Code: Select all
printf("<input type=\"text\" name=\"iName\" value=\"%s\" />", $str);
or
Code: Select all
<input type="text" name="iName" value="<?php print($str); ?>" />
Sheridan
Forum Newbie
Posts: 18 Joined: Sat May 31, 2008 1:50 pm
Post
by Sheridan » Sat May 31, 2008 3:14 pm
Hi:
The printf() function did the trick. Thanks a million.
LSJason
Forum Commoner
Posts: 45 Joined: Mon May 12, 2008 4:43 pm
Post
by LSJason » Sat May 31, 2008 9:26 pm
For future reference, you can do this:
Code: Select all
$row = mysql_fetch_row($result);
$str = $row[1];
$str .= ", ";
$str .= $row[2];
echo '<form action="testSendQueryData.php" method="get">';
echo '<br>';
echo '<input type="text" name="iName" value = '.$str.'>';
echo '<input type="submit">';