Kei Garrix
Kei Garrix

Reputation: 31

Put the information from MySQL into the textarea, without extra spaces?

My code is giving me a problem: When I save the information into the database, the formatting is being preserved, but when I put the information into the textarea, there are a lot of extra spaces.

Screenshoot: http://i1226.photobucket.com/albums/ee416/realodix/Photo%20Blog/description_zps8f9c858c.jpg

<?php
    $id = $_GET['id'];
?>

<form id="form1" name="form1" method="post" enctype="multipart/form-data" action="wbpl_add-edit.php?action=updateproduct&id=<?php echo $id ?>">
    <td>
    <table>

<?php
    $sql="select * from wbpl_product
          where kd_product='$id'";
    $result=mysql_query($sql) or die(mysql_error());
    while($rows=mysql_fetch_array($result)){
    ?>

<tr>
<td width="120">Deskription</td>
<td width="350">
    <textarea name="product_deskripsi" rows="5" style="width: 512px;"><?php echo htmlspecialchars($rows['deskripsi']);?></textarea>
</td>
</tr>

<?php } ?>

<tr>
    <td>&nbsp;</td>

    <td>
    <input class="btn" type="submit" name="tambah" value="Update" />
    </td>
</tr>

<tr>
    <td colspan='2'><div id="form1_errorloc" style="color:red"></div></td>
</tr>

</table></td>
</form>

Upvotes: 1

Views: 884

Answers (2)

Arthur Brown
Arthur Brown

Reputation: 41

Try this:

<textarea name="product_deskripsi" rows="5" style="width: 512px;">

add wrap

<textarea name="product_deskripsi" rows="5" wrap="virtual" style="width: 512px;">

You can use wrap: off, soft, hard, virtual or physical

Upvotes: 0

Ryan
Ryan

Reputation: 1338

Each time you save that form, the whitespace after <textarea> will be prepended to the value, remove the spacing after <textarea> like the below:

<textarea name="product_deskripsi" rows="5" style="width: 512px;"><?php echo htmlspecialchars($rows['deskripsi']);?></textarea>

Upvotes: 3

Related Questions