CodeThatEditor Example - Data saving at the database

CodeThatEditor Example - Data saving at the database

<php
if (!empty($data)) {
	//here some data to save
	if (!empty($id)) {
		//modify exist record
		$query = "update editor_data set note='$data' where id=$id";
	}
	else {
		//add new one
		$query = "insert into editor_data (note) values ('$data')";
	};
	//save data
	mysql_query($query);
	$error = mysql_error();
	if ($error) print($error);
	else print("<p>All CodeThatEditor data have been
	successfully stored at the server database!");
};
//read data
if (empty($id)) {
	$query = "select max(id) from editor_data";
	$result = mysql_query($query);
	if ($rs = mysql_fetch_row($result)) $id = $rs[0];
	else $id = 0;
};
$query = "select * from editor_data where id=$id";
$result = mysql_query($query);
if ($rs = mysql_fetch_array($result))
$text = str_replace("\r", "",
str_replace("\n", "'\n+'",
str_replace("'", "&#39;", $rs["note"])));
else $text = ""; 
?>
<html>
 <head>
  <title>Editor Test</title>
  <link href="/common_codethat.css" rel="stylesheet" type="text/css">	
  <script language="javascript1.2">
<!--
codethatsdk.js">
//-->
</script>	
  <script language="javascript" src="codethateditorpro.js"></script>         
 </head>
 <body>
  
<script language="javascript1.2">
<!--
var editorDef = {
	text : '<?php print($text);?>',
	style : {
		width : 400,
		height : 200,
		defaultClass : {
			backgroundcolor : "#ffffff",
			bordercolor : "#efefe0",
			borderstyle : "inset",
			borderwidth : 2
		}
	}
};
var editor = new CEditor('sample', editorDef);
editor.create(); 
//-->
</script> 

<FORM name=exportForm method=post>
<INPUT type=hidden name=data value=""> 
<SELECT name=id><option value="">New note</option>
<php
$query = "select id from editor_data";
$result = mysql_query($query);
while ($rs = mysql_fetch_row($result))
print("<option value=\"$rs[0]\" " .
(($id == $rs[0])?" selected" : "") .
">Note #$rs[0]</option>"); 
?>
</SELECT> 
<INPUT type=submit value="Read note" name=db>  
<INPUT type=submit value="Save note" name=dbsave 
onClick="exportForm.data.value=CodeThatEditors['sample'].getText()"> 
</FORM>