Reputation: 93
echo " <table bgcolor='#d3fcfe' align='center'> ";
while ($row = mysql_fetch_array($result)) {
echo '</div> <tr onmouseout="this.bgColor=\'#d3fcfe\';" onmouseover= "this .bgColor=\'#fffdcd\';" > ';
$numq2=$row['username'] ;
{
echo '<td ><div class="iddiv"> <input name="" type="text" value="$numq2" /> <div> </td> ';
}
echo ' </table>';
}
i want to output $numq2 Var's data into the value of the textfield.but something is wrong with my code.it prinout the value of textfield as "$numq2".what's wrong with my script?
Upvotes: 2
Views: 701
Reputation: 970
try
echo <td ><div class="iddiv"> <input name="" type="text" value="<?php echo $numq2;?>" /> <div></td>';
Upvotes: 0
Reputation: 5316
You are using single quotes around your string.
Anything wrapped in single quotes gets output as is, and does not get parsed.
Double quotes runs your string through the parser and any variables get replaced with their values.
You need to either break out of the single quotes and concatenate your variable as follows:
echo 'My value ' . $value . ' is the best value';
Or you need to wrap your string in double quotes and wrap your variable in { } as follows:
echo "My value {$value} is the best value";
Upvotes: 0
Reputation: 1172
This
echo '<td ><div class="iddiv"> <input name="" type="text" value="$numq2" /> <div> </td> ';
should become
echo '<td ><div class="iddiv"> <input name="" type="text" value="'.$numq2.'" /> <div> </td> ';
Notice the '.
and .'
around your $numq2
Upvotes: 1
Reputation: 784958
Just use your echo like this:
echo '<td ><div class="iddiv"> <input name="" type="text" value="' . $row['username'] . '" /> <div> </td> ';
Upvotes: 2
Reputation: 7090
wrong quote use.
use either
echo '...value="'.$numq2.'" />...';
or
echo " ... value=\"$numq2\" /> ...";
Upvotes: 1
Reputation: 28174
You need to use double quotes "
for your strings in order for variables to be evaluated. Escape the double quotes in your HTML to have one long string.
Alternatively, you can use concatenation, allowing you to use single quotes around your HTML, and then concatenating the evaluated variables in between, like so:
echo '<td ><div class="iddiv"> <input name="" type="text" value="'.$numq2.'" /> <div> </td> ';
Upvotes: 4