Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Problems with PHP and TinyMCE

Posted on 2009-04-28
4
Medium Priority
?
380 Views
Last Modified: 2013-12-13
Hello,

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/numyspace.co.uk/web_users/home/~unn_r031923/public_html/Testing/index.php 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.

http://www.numyspace.co.uk/~unn_r031923/Testing/index.php
<b>index.php</b>
------------------------------
<?php
  include('header.html');
 
// 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")) {
    include("pages/$page");
 
// If page doesn't exist, give an error message.
  } else {
    echo("<h1 align=\"center\">Page cannot be found</h1>\n");
  }
 
 
  include('footer.html');
?>

Open in new window

0
Comment
Question by:LearningPHPMySQL
  • 2
4 Comments
 
LVL 17

Expert Comment

by:Chris Harte
ID: 24251165
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']))
{
}
0
 

Author Comment

by:LearningPHPMySQL
ID: 24251459
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 http://www.numyspace.co.uk/~unn_r031923/Testing/secure/index.php

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/numyspace.co.uk/web_users/home/~unn_r031923/public_html/Testing/secure/index.php on line 23

Notice: Undefined variable: page in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_r031923/public_html/Testing/secure/index.php on line 24

Notice: Undefined variable: text in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_r031923/public_html/Testing/secure/index.php 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.
<?php
include("header.html");
 
// 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");
  include("../footer.html");
  exit;
}
 
if (isset($_POST['page'])) {
  $handle = fopen("../pages/$page", 'w');
  fwrite($handle, $_POST['page']);
  fclose($handle);
  //include("../pages/$page");
  include("../footer.html");
  exit;
}
 
if (file_exists("../pages/$page")) {
  $FILE = fopen("../pages/$page", "rt");
  while (!feof($FILE)) {
    $text .= fgets($FILE);
  }
  fclose($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">
tinyMCE.init({
 
// 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",
 
 
});
</script>
EOM;
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(htmlspecialchars($text));
echo("</textarea>\n");
echo("<input type=\"submit\" value=\"Save\">\n");
echo("</form>\n");
 
 
include("footer.html");
 
?>

Open in new window

0
 
LVL 4

Accepted Solution

by:
joep1978 earned 2000 total points
ID: 24251529
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.
0
 

Author Comment

by:LearningPHPMySQL
ID: 24251661
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 ?
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Suggested Courses
Course of the Month20 days, 21 hours left to enroll

810 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