Page 1 of 1

Displaying text from a DB

PostPosted: Sat Jan 27, 2007 4:12 pm
by Dashman

I am trying to use WYM Editor in a PHP and MySQL - based CMS.
If I write new content, I can get it to publish to the DB fine. Now, if I want to edit an article that I have written previously, I get the article based on ID from the DB, but where/how could I get the content to be displayed in the editor?

Does this make sense?


PostPosted: Mon Jan 29, 2007 11:36 am
by jfh
Of course, this makes sense :)

Just put the content in the div id="editor", so you can edit it.


PostPosted: Mon Jan 29, 2007 11:40 am
by Dashman
Hi, thanks for the reply.

I have actually just got it firgured out this morning:

Code: Select all
<div contentEditable name="editor" id="editor"
         print $body;

Where $body is the data retrieved ...

Thanks again,

posting to database

PostPosted: Fri Jun 15, 2007 2:53 am
by worxguy
I'm having the opposite problem. I can fetch content from the database and display it in WYMeditor. But, I can't save the edited content back to the database. I'm using php and mysql. Does WYMeditor produce a variable that holds the edited content?

All help appreciated,

PostPosted: Fri Jun 15, 2007 7:28 am
by jfh
In 0.2.2, you need to retrieve the content from the textarea 'txthtml'.
You can also get the XHTML by calling getCleanHTML().

In 0.3, wym.update() updates the textarea value.
You can also get the XHTML by calling wym.xhtml().

PostPosted: Fri Jun 15, 2007 9:21 pm
by worxguy
Yep. That's always been my problem. I'm mediocre with php and mysql but an extreme novice with javascript. I've been thru fck and spaw editors and was hoping that WYMeditor had been dumbed down enough to accommodate my meager skills.

Here's my code, and I'm totally lost on calling wym.update (). How do I call it and where should it go? I am using 0.3.

All help greatly appreciated and thanks for your prompt reply,
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<link rel="stylesheet" type="text/css" media="screen" href="../wymeditor/skins/default/screen.css" />
<script type="text/javascript" src="../jquery/jquery.js"></script>
<script type="text/javascript" src="../wymeditor/jquery.wymeditor.js"></script>
<script type="text/javascript">

var $j = jQuery.noConflict();

$j(function() {


//contact the database

//fetch the content
if (isset($_GET['id'])) {

$id = $_GET["id"];


$query = "SELECT id, pageName, content FROM content WHERE id = $id";
$result = mysql_query($query) or die('Error : ' . mysql_error());
list($id, $pageName, $content) = mysql_fetch_array($result, MYSQL_NUM);

<form method="post" action="<?=$_SERVER['PHP_SELF']?>">
<input type="hidden" name="id" value="<?=$id;?>">
<textarea class="wymeditor">
print $content
<input type="submit" class="wymupdate" />

PostPosted: Sat Jun 16, 2007 7:50 am
by jfh
You don't need to call wym.update() here because you use a submit button with the class 'wymupdate', which actually does the job.
(You can optionally use other elements/events instead of a submit button, see Customization.)

On the other hand, I don't see in your example the code which will handle the posted content, e.g. something like:
Code: Select all
if(isset($_POST['id'])) {
  //update the DB

BTW, don't forget to put a 'name' attribute in the textarea!
And IMHO it's a good practice to use PHP's mysql_real_escape_string() to e.g. prevent SQL injection.

PostPosted: Tue Jun 19, 2007 3:32 pm
by worxguy
Thank you so much, JFH!

The isset problem was the basis for my "what's next" query, and you supplied the answer as a BTW thought. I had my name labels jumbled. :oops:

I'm extremely glad I found WYMeditor and will keep working with it until I can achieve production status.

thanks again,

PostPosted: Wed Jun 20, 2007 8:10 am
by jfh
You're welcome. :)