Reputation: 111
I have large html code inside my DATABASE. I need to get that into textarea for editing purpose. I can do that all but i have problem when it is displaying code into textarea. Half code is inside of textarea but other half display form not code and it display it out of textarea. (See Picture ).
Passing data from DATABASE:
<?php
include_once("scripts/connect.php");
$id = $_GET['id'];
$result = mysqli_query($mysqli, "SELECT * FROM formsAndCategories WHERE id=$id");
while($res = mysqli_fetch_array($result))
{
$category = $res['category'];
$form = $res['form'];
}?>
Displaying code from DATABASE (issue is with textarea. its displaying wrong on page):
<form name="form1" method="post" action="edit.php">
<label class="fb-textarea-label">Form Code</label><textarea name="form" class="form-control" rows="25"><?php echo $form;?></textarea>
<label class="fb-text-label">Category</label> <td><input type="text" name="category" class="form-control" value="<?php echo $category;?>"></td>
<input type="hidden" name="id" value="<?php echo $_GET['id'];?>"></td>
<input type="submit" class="btn btn-success" name="update" value="Update"></td>
</form>
So far i tryed to do that on plain page. I was thinking maby those all (bootstraps, jquery and css etc) are ruining it all. But nothing.
Then i found out that there is no character limit in textarea but anyway i tryed to set character limit with maxlength="200000"
.
Then i tryed different code because i was thinking maby there is problem with html form code but nothing.
If it is not possible in this way then maby there is different way to do this ? If somebody can help me out with this it would be great. Thank You.
Upvotes: 0
Views: 91
Reputation: 1973
Following code will escape HTML characters. In the code above, HTML characters are not escaped and directly appending HTML to text box is causing the HTML breakup.
May be following solution will work.
<textarea name="form" class="form-control" rows="25"><?php echo htmlentities($form);?></textarea>
or
<textarea name="form" class="form-control" rows="25"><?php echo htmlspecialchars($form);?></textarea>
Upvotes: 1