Hi,
I'm trying to post the results of a popular rich text editor, to a database.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Edit Page")</title>
<script language="JavaScript" type="text/javascript" src="richtext.js"></script>
</head>
<body>
<h2>Edit Promotional Page</h2>
<form name="RTEDemo" action="" method="post">
<script language="JavaScript" type="text/javascript">
<?
//MY STUFF
REQUIRE("./connx.php");
$data = @mysql_query("SELECT * FROM post");
WHILE ($row = mysql_fetch_array($data)){
$strHTML = ($row[text]);
}
//END MY STUFF
$content = "$strHTML";
$content = RTESafe($content);
?>
//writeRichText(fieldname, html, width, height, buttons)
writeRichText('rte1', '<?=$content?>', 520, 200, true);
//uncomment this section to see a demo of multiple RTE's on one page
//document.writeln('<br><br>');
//writeRichText('rte2', '', 450, 100, true);
//-->
</script>
<noscript><p><b>Javascript must be enabled to use this form.</b></p></noscript>
<p>Click submit to show the value of the text box.</p>
<!--// MORE MY STUFF //-->
<p><input type="button" name="post_text" value="Submit"></p>
</form>
<?
if ($post_text == "Submit") {
$sql = "UPDATE TABLE post SET
text = "$rte1"; //unexpected T_Variable?
}
?>
<!--// END MORE MY STUFF //-->
</body>
</html>
<?
//php example
function RTESafe($strText) {
//returns safe code for preloading in the RTE
$tmpString = trim($strText);
//convert all types of single quotes
$tmpString = str_replace(chr(145), chr(39), $tmpString);
$tmpString = str_replace(chr(146), chr(39), $tmpString);
$tmpString = str_replace("'", "'", $tmpString);
//convert all types of double quotes
$tmpString = str_replace(chr(147), chr(34), $tmpString);
$tmpString = str_replace(chr(148), chr(34), $tmpString);
// $tmpString = str_replace("\"", "\"", $tmpString);
//replace carriage returns & line feeds
$tmpString = str_replace(chr(10), " ", $tmpString);
$tmpString = str_replace(chr(13), " ", $tmpString);
return $tmpString;
}
?>
As it stands, i've got the contents of the 'text' field loading into the editor. But the bit where i try to submit the edited text back to the database generates a syntax error, (unexpected T_VARIABLE in the line that says text = "$rte1"; ). I dunno, it looks to me just like the examples in my book. It wouldn't surprise me if i was using the wrong variables for the procedure, but i'm baffled that PHP doesn't expect one at all.
Anyway the original RTE distribution is attached, unmolested, in case anyone needs a reference to see what i screwed up, or just needs a rich text editor. 😉 It's nice and small.
The original file used a js function to post the results to an alert box. I REALLY hope i don't need javascript to make this work, because i never had any skillz whatsoever with that.
TIA,
JB