View Full Version : TinyMCE Integration
Dan
February 21st, 2010, 04:26
Hey folks.
I downloaded TinyMCE and followed the instructions to install and integrate it into a php web page. All fine and dandy.
I also figured out how to get the info to the page by adding the following to the section where I wanted the content to show:
<?php
echo(stripslashes($_POST['content']));
?>
However, when I refresh that page I get the following:
Notice: Undefined index: content in C:\wamp\www\site\index.php on line 87
I also would like for the content that was placed into the editor to remain there so it can be edited in future without losing data. Something like what Joomla does? Can anyone please give me a simple english lesson on this?
I have tried the TinyMCE support forums but was told to ask elsewhere.
I have also searched Google but to no avail.
I know my options are:
1. Have the editor submit the content to MySQL and have the editor save the changes within itself somehow.
2. Submit the data to a flat file and have that data sent to the targetted area on the page.
Any ideas? Suggestions?
Thanks in advance.
Dynash
February 21st, 2010, 05:06
The first option would be your best bet, flat-file would be risky. Take a leaf out of WordPress' book.
Dan
February 21st, 2010, 05:38
Thanks Dynash.
I have created the DB and the row I want to use to store content and send it to the index page.
The Database:
CREATE TABLE `content` (
`indexcontent` int(10) unsigned default NULL,
PRIMARY KEY (`indexcontent`)
);
INSERT INTO `content` (`indexcontent`) VALUES ('This is default text from the database.');
I am new to MySQL really so not sure if that's even right. Although it imports ok without errors.
Here is the part in the TinyMCE code that sends the content to the database, or so I hoped:
<form method="post" action="../index.php">
<textarea name="content" style="width:500px; height: 300px;">Content </textarea><br />
<input type="submit" name="submit" value="Post">
</form>
and the part in index.php that collects from the DB, or so I would have hoped:
<?php
echo(stripslashes($_POST['indexcontent']));
?>
I did all this and it won't work. Still getting the same error as before.
If anyone can help solve this I would really appreciate it.
Dynash
February 21st, 2010, 06:54
Where you have $_POST, all that does it take the information (In this case, content) from the form after it is submitted. It doesn't stay around for long. What you need to do is create two separate SQL statements in PHP (INSERT & SELECT) in order to store and retrieve the information from your database when needed.
This SQL table would be better:
CREATE TABLE IF NOT EXISTS `content` (
`indexcontent` varchar(255) NOT NULL,
PRIMARY KEY (`indexcontent`)
);
Then where you get the info from $_POST, do something that is close to this:
<?php
mysql_connect('localhost', 'root', 'root') or die (mysql_error());
mysql_select_db('db') or die (mysql_error());
$Content = stripslashes($_POST['content']); // 'content' because you have that as the name="" in the form.
$SendContent = mysql_query("INSERT INTO `content` (`indexcontent`) VALUES (`$Content`)"); // now that should store your info into the database, use some if statements to give feedback of failed/success.
$GetContent = mysql_query("SELECT `indexcontent` FROM `content`");
foreach ( $GetContent as $Contents) {
echo "$Contents\n";
}
?>
You'll have to check if this works for you, it was just a quick rep of what you should be doing, nothing "great".
Dan
February 21st, 2010, 07:08
Nah.
Getting the following errors:
Notice: Undefined index: content in C:\wamp\www\site\admin\editindex.php on line 59
Warning: mysql_query() [function.mysql-query]: Access denied for user 'SYSTEM'@'localhost' (using password: NO) in C:\wamp\www\site\admin\editindex.php on line 60
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\wamp\www\site\admin\editindex.php on line 60
Warning: mysql_query() [function.mysql-query]: Access denied for user 'SYSTEM'@'localhost' (using password: NO) in C:\wamp\www\site\admin\editindex.php on line 62
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\wamp\www\site\admin\editindex.php on line 62
Warning: Invalid argument supplied for foreach() in C:\wamp\www\site\admin\editindex.php on line 64
Don't know where SYSTEM is coming from.
Dynash
February 21st, 2010, 11:32
You don't even have paths? - C:wampwwwsiteadmineditindex.php :s
Dan
February 21st, 2010, 12:03
You don't even have paths? - C:wampwwwsiteadmineditindex.php :s
That's the way they were picked up and thrown here on FWS.
iBrightDev
February 22nd, 2010, 15:05
do you have the mysql connect statement built properly man?
$link = mysql_connect('HOSTNAME HERE', 'MYSQL USER HERE', 'MYSQL PASSWORD HERE');
mysql_select_db('DATABASE NAME HERE',$link) or die('Could not connect to database<br/><br/><strong>MySQL Error:</strong><br/>'.mysql_error());
Dan
February 22nd, 2010, 20:08
do you have the mysql connect statement built properly man?
$link = mysql_connect('HOSTNAME HERE', 'MYSQL USER HERE', 'MYSQL PASSWORD HERE');
mysql_select_db('DATABASE NAME HERE',$link) or die('Could not connect to database<br/><br/><strong>MySQL Error:</strong><br/>'.mysql_error());
Hey Justin,
What I have mate is the database info in a config file. So at the top of each page that needs to connect I have
include_once 'includes/config.php' ;
Not sure if that's the correct way or not.
I know I am known for forking applications and releasing them as my own. I am over that. I want to make an honest go at something. I am almost there. Just need to get TinyMCE working.
Dan
February 23rd, 2010, 10:56
Got this sorted guys. Thanks anyways for the help :)
iBrightDev
February 23rd, 2010, 12:19
glad you got it. :)
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.