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> </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 {…..