I am basically trying to output data from database. It works just fine when its echo'ing it out, but when I have a textbox and want to put the output into the value attribute in
This is my code:
while($row = mysql_fetch_assoc($retval))
{
echo "
Kontakt / Infos:
<form action='edit.php?update' method='POST'>
<input type='hidden' name='idtoedit' value='".$editid."' />
<input name='zuname' type='text' size='30' value={$row['name']}>
<input type='submit' value='Speichern'>
</form>
";
}
For example if the data in MySQL is "Hello my name is Maxim", I only see "Hello" in the textbox. What's the problem? Thanks in advance
The problem is that your value
does not have quotes
around it's variable
so it breaks on white space, and the rest is seen as properties.
value=\"{$row['name']}\"
use '
before and after {$row['name']}
as
while($row = mysql_fetch_assoc($retval))
{
echo "
Kontakt / Infos:
<form action='edit.php?update' method='POST'>
<input type='hidden' name='idtoedit' value='".$editid."' />
<input name='zuname' type='text' size='30' value='{$row['name']}'>
<input type='submit' value='Speichern'>
</form>
";
}
Try this one
while($row = mysql_fetch_assoc($retval))
{
echo "
Kontakt / Infos:
<form action='edit.php?update' method='POST'>
<input type='hidden' name='idtoedit' value='".$editid."' />
<input name='zuname' type='text' size='30' value=".$row['name'].">
<input type='submit' value='Speichern'>
</form>
";
}
TRY
while($row = mysql_fetch_assoc($retval))
{
printf("
Kontakt / Infos:
<form action='edit.php?update' method='POST'>
<input type='hidden' name='idtoedit' value='".$editid."' />
<input name='zuname' type='text' size='30' value='%s'>
<input type='submit' value='Speichern'>
</form>
",$row['name']);
}
In my opinion, better to do like this :
while($row = mysql_fetch_assoc($retval))
{ ?>
Kontakt / Infos:
<form action='edit.php?update' method='POST'>
<input type='hidden' name='idtoedit' value="<?=$editid?>" />
<input name='zuname' type='text' size='30' value="<?=$row['name']?>">
<input type='submit' value='Speichern'>
</form>
<?
}
You have here a lot of html code. Putting this in a echo make the code less understandable.