/    Sign up×
Community /Pin to ProfileBookmark

Preview text and keep the text in the textarea

I have an html practice board written in PHP. It lets the user enter html code and then displays what the code will produce. Very similar to practiceboard.com and others. It works fine as far as storing everything in the database and outputting the url where the user can come back later and view the page. The problem is once a user clicks to see the html, all the text is removed from the textarea. I need the text to stay inside the textarea so users can edit the code, refer others to the link, etc.

I’m not sure which part of the code needs changed.

[code]
……..<form method=”post” action=”index.php”>
<td><textarea name=”Code” cols=”60″ rows=”10″></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td bgcolor=”#FFCC99″ style=”height: 25px;”>

<table width=”100%” border=”0″ cellpadding=”0″ cellspacing=”0″>
<tr>
<td width=”35%” align=”center”><input type=”submit” name=”Submit” value=”Click To View HTML!”></td>
<td width=”15%” align=”center”><input type=”reset” name=”Reset” value=”Reset”></td>
<td width=”15%” align=”center”><input type=”submit” name=”Clear” value=”Clear”></td>
</form>
</tr>
</table>

</td>

</center> </tr>
</table>

<?php

if (isset($_POST[‘Submit’])) { // checks to see if form has been submitted

echo “<br><br>”;

connect();

$InsertNewHTML = mysql_query(“INSERT INTO HTML_Practice VALUES(”,’$Code’)”)
or die(“Cannot insert HTML into table!”);
// adds the users submitted HTML to the database

$GetLastId = mysql_query(“SELECT * FROM HTML_Practice ORDER BY Id DESC LIMIT 0,1”);
while ($Get = mysql_fetch_array($GetLastId)) {

$LastId = $Get[‘Id’];
// gets the unique id of the HTML the user submitted for use with giving the user a link to the HTML that they can view again and again

}

mysql_close();….
<?php

if (isset($_POST[‘Submit’])) {

$Code = str_replace(“””, “‘”, $_POST[‘Code’]); // replaces all quotes with printable quotes
$Code = str_replace(“\”, “”, $Code); // replaces all unwanted backslashes
$Code = eregi_replace(“bgcolor=’#[0-9][0-9][0-9][0-9][0-9][0-9]'”, “bgcolor=’#ffffff'”, $Code);
// so the user cant turn the screen black 🙂

echo “<hr>” . $Code . “<hr>”;

} else if (isset($Id)) {

connect();

$GetHTML = mysql_query(“SELECT * FROM HTML_Practice WHERE Id=’$Id'”);
// gets the id selected HTML from the database
while ($Get = mysql_fetch_array($GetHTML)) {

$HTML = str_replace(“””, “‘”, $Get[‘Code’]);
$HTML = str_replace(“\”, “”, $HTML);
$HTML = eregi_replace(“bgcolor=’#[0-9][0-9][0-9][0-9][0-9][0-9]'”, “bgcolor=’#ffffff'”, $HTML);
echo “<hr>” . $HTML . “<hr>”;

}

mysql_close();

} else {…..
[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@bokehFeb 20.2005 — [code=php]<td><textarea name="Code" cols="60" rows="10"><?php print("$Code"); ?></textarea></td>[/code]
Copy linkTweet thisAlerts:
@phpnoviceFeb 20.2005 — ...and the following is the shorthand version of the same thing:
[code=php]
<td><textarea name="Code" cols="60" rows="10"><?=$Code?></textarea></td>
[/code]
×

Success!

Help @wvmlt spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...