I've only just come across FCKeditor and would like to use it on a website I've begin to create.
However, I want to use it to create and edit data thats held in a mysql server. I'm getting pretty good at php and mysql now so that area shouldn't be a problem, but how can I integrate with this editor?
The 'data' it's going to edit is just text, as I want to use it for the front end of a simple admin area where people can type up and save news stories (into the mysql table), and possibly re-load it to alter later on if they need to.
Is it possible, and where in the code should I be looking? There are about 5/6 'demo' files in the download - do I have to change every single one???!!!
Tue, 10/02/2007 - 11:40
#1
Re: PHP & mysql integration
Take some time, read docs http://wiki.fckeditor.net/ and you'll find the answer
There are multiple demo files because each script covers some interesting aspect of FCKeditor.
Tip: take a look how data is assigned to FCKeditor object:
(it may differ a bit in other languages.)
Simply assign to value property data pulled from database.
Wiktor Walc
CTO, CKSource - http://cksource.com
--
Follow CKEditor on: Twitter | Facebook | Google+
Re: PHP & mysql integration
I used this:
this:
and this:
but it will not display the information.
I'm using the javascript version inside my php form. I can do a View Source and see that the information was pulled from the database, but it will not display.
I didn't see anything in the Doc's that deals with using fckeditor to edit database information, that was entered in with fckeditor. If it were to display the information, I don't know if it would be in a WYSIWYG format or HTML. If it would only display the information in HTML (showing all the tags) you might as well just use a textarea.
I would like to use fckeditor in both an add_ibfo.php script and an edit_info.php script or is it impossible to use fckeditor an edit script?
Re: PHP & mysql integration
Then, before saving data to DB, use one of dedicated functions to escape strings, like mysql_real_escape_string - only such function will prevent you against SQL injection.
Please note that even the example at php.net (below description of get_magic_quotes_gpc) is generally wrong: instead of adding slashes if magic_quotes is off, it's better to strip slashes if it's on.
Now regarding this code:
this one is correct, but under one condition, that if you do:
just before doing this assignment, you will see exactly that string you want to edit (without slashes).
So generally the problem is that your string is wrongly escaped.
Wiktor Walc
CTO, CKSource - http://cksource.com
--
Follow CKEditor on: Twitter | Facebook | Google+
Re: PHP & mysql integration
When I pull from the database to display the information I use this:
I don't know how to implement your suggestion:
Like this?
Re: PHP & mysql integration
And got this on the front side:
The above showed on the Web page, but without the fckeditor toolbar and editing box. But at least something showed up, so we're getting closer to the desire effect. Ultimately, I want to be able to display what was entered into the database the first time (in the WYSIWYG format), so that it can be edited and the updated information put back into the database.
Re: PHP & mysql integration
Hi,
I suggested to use var_dump to see what string are you trying to edit, sorry if I pointed you to the wrong direction.
Took me some time to figure out what's the real problem
You are using Javascript to assign string with multiple line breaks. It's not possible (...) to assign string with \r\n to javascript variable, like you can do it in PHP.
If string contains more than one line, you need to put in a backslash at the end of each line to let the browser know it's continuing the string to the next line.
But it's simply complicating your live.
I suggest that you'd better use FCKeditor's PHP class. Take a look at _samples/php. Create FCKeditor in a similar way like you see in example, and assign content pulled from db just with one statement:
Wiktor Walc
CTO, CKSource - http://cksource.com
--
Follow CKEditor on: Twitter | Facebook | Google+
Re: PHP & mysql integration
Re: PHP & mysql integration
-Nathan
Re: PHP & mysql integration
Please, instead of PM, post everything in public because other people might find that information useful. If you had trouble to understand the samples then maybe you can suggest other samples, instructions or whatever, but do it here or in the wiki so everybody can benefit from that information
Re: PHP & mysql integration
For storage into a database the PHP htmlspecialchars() function step is NOT needed. Below is the function that I created to display my editor box and display the MySQL content to the box. This function only takes data provided to it so just simply calling it will provide you with errors. Pull your content from your database and then call the function when you extract the data from your database.
The config settings that I use are:
BasePath: set to the folder I have the FCKeditor stored in and must be relative to file that function is called from NOT the file that the function is stored in (ie. from index.php if the function is called here NOT _scripts/functions.php where the function below is placed.)
Config["ToolbarStartExpanded"]: set to either true or false depending on if you wanted the toolbar fully expanded when created. The function I used this for was for multiple boxes and having them all expanded was confusing so I just closed them all to begin with.
ToolbarSet: I created a new ToolbarSet in the fckconfig.js file that removed some functions that I didn't need my client to use and weren't needed for the project. Make sure the call here is an actual defined ToolbarSet or you will get an error.
Value: This is where the content that will display in the box upon creation is placed. The $message variable is what is set outside of this function. When called using a $editor = editorBox(1,$content) <- the $content variable is the message I want to display. The function then sets this (as $message) to the Value parameter and creates the editor with this content already displayed in the box.
The $id and the $message variable requirements were so I could have multiple boxes displayed without having to paste the same code multiple times. It made it much easier to increase a number through PHP and have the code loop through my content and create my editor boxes. The $id is what the name="" attribute of my textarea became since I had multiple boxes and wanted a quick way to identify which box went with which data.
Play around with it to see if it's what you need or not.
Re: PHP & mysql integration
I was struggling with the same problem that FCKeditor wasnt showing the data that was pulled from database correctly in FCKeditor. So I played around and finally it worked(dont its the right solution, but it worked for me). I removed

----removed---------
if ( get_magic_quotes_gpc() )
$postedValue = htmlspecialchars( stripslashes( $value ) ) ;
else
$postedValue = htmlspecialchars( $value ) ;
----removed---------
and simply used the below mentioned code
$postedValue=mysql_real_escape_string($value);
I think it'll solve your problem as well.
Good Luck