Problems with PHP and TinyMCE

Posted on 2009-04-28
Last Modified: 2013-12-13

I am building a WYSIWYG application for my project. I have been using TinyMCE for this, and locally using WAMP this has been working fine.

Now though, when i transfer onto my live webserver i am running into problems.

All the body of the pages are in text files, and people will beable to edit the txt file and it will then change on the webpage.

What is happening is i am getting the following error message appearing on screen "Notice: Undefined index: page in /var/www/vhosts/ on line 5"

Then underneath that, it is displaying the correct  text from the associated text file. So for this page  is my home page which is index.php, it picks up home.txt.  

Could anybody help me with this error message please. As i said, it seems to be working locally using WAMP but not LIVE using my College webserver.





// Set $page to "home.txt" if a parameter isn't passed

  if ($_GET['page']) {

    $page = $_GET['page'] . '.txt';

  } else {

    $page = 'home.txt';



// Check to see if file exists and include it in.

  if (file_exists("pages/$page")) {



// If page doesn't exist, give an error message.

  } else {

    echo("<h1 align=\"center\">Page cannot be found</h1>\n");






Open in new window

Question by:LearningPHPMySQL
    LVL 16

    Expert Comment

    by:Chris Harte
    Undefined index means that the 'page' index in the $_GET array is not set. Use the isset function in your conditional

    if (isset($_GET['page']))

    Author Comment

    Thanks, that has sorted that problem for just viewing the pages.

    I have kind of the same problem when i want to edit my pages.  hen you want to edit a page, you are taken to the secure directory (I will add a login page later).

    So i will be first taken to

    This would be the home page, ready to be edited. It should show the TinyMCE editor on this page, with home.txt loaded into it,  but at the moment it i just showing a box without the toobar, and also the following errors

    Notice: Undefined variable: page in /var/www/vhosts/ on line 23

    Notice: Undefined variable: page in /var/www/vhosts/ on line 24

    Notice: Undefined variable: text in /var/www/vhosts/ on line 26

    Basically what happens is, or what i want to happen, is the page to load, edit the text, click save, and then the updated page is then shown in the browser.
    // Get the page name from the query string
    if (isset($_GET['page'])){
    $page = $_GET['page'] .'.txt';
    $page = "../pages/home.txt";
      echo("<h1>Page name not specified</h1>\n");
    if (isset($_POST['page'])) {
      $handle = fopen("../pages/$page", 'w');
      fwrite($handle, $_POST['page']);
    if (file_exists("../pages/$page")) {
      $FILE = fopen("../pages/$page", "rt");
      while (!feof($FILE)) {
        $text .= fgets($FILE);
    } else {
       echo("<h1>New Page: $page</h1>\n");
      $text = "<p></p>";
    echo <<< EOM
    <script language="javascript" type="text/javascript" src="/Testing/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
    <script language="javascript" type="text/javascript">
    // General options
    mode : "textareas",
    theme : "advanced",
    plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager",
    // Theme options
    theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
    theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
    theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|",
    theme_advanced_buttons4 : "moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,|,insertfile,insertimage",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_resizing : true,
    // Example content CSS (should be your site CSS)
    content_css : "css/example.css",
    // Drop lists for link/image/media/template dialogs
    template_external_list_url : "js/template_list.js",
    external_link_list_url : "js/link_list.js",
    external_image_list_url : "js/image_list.js",
    media_external_list_url : "js/media_list.js",
    if (isset($_GET['page'])){
    $page = $_GET['page'] . '.txt';
    $a = $_GET['page'];
    $a = 1; //$_SERVER['PHP_SELF'];
    $this_page = $_SERVER['PHP_SELF'];
    $query_string = $_SERVER['QUERY_STRING'];
    echo("<form method=\"post\" action=\"$this_page?$query_string\">\n");
    echo("<textarea id=\"page\" name=\"page\" rows=25 cols=80>\n");
    echo("<input type=\"submit\" value=\"Save\">\n");

    Open in new window

    LVL 4

    Accepted Solution

    You don't need the notices being output as error messages - they're not.  There's nothing wrong with an undefined variable if you mean it to be undefined.

    Create a .htaccess file if you haven't already and add the line:-

    php_value error_reporting 6135

    That should hide the Notice error messages.

    Author Comment

    I have uploaded the .htaccess file and it has got rid of the error messeges,  but it is not picking up

    1. the associated text file in the tinyMCE editor, and
    2. the tinyMCE toolbar on the top is not appearing anymore.

    I have checked and it is pointing to the correct directory ?

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Introduction HyperText Transfer Protocol ( or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
    Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
    This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now