Edit Contents with TinyMCE and PHP/MYSQL

Thread Solved

Join Date: Jun 2007
Posts: 1,474
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 128
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Nearly a Posting Virtuoso

Edit Contents with TinyMCE and PHP/MYSQL

 
0
  #1
Oct 6th, 2009
Hi All,
I have made simple CMS with PHP/MYSQL. It make use of TinyMCE as Javascript editor. I can delete as well as add the contents. But How can I load the contents from database to TinyMCE for editing and saving? Here is my PHP code to add contents using TinyMCE (No database connections population et cetera)

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
  5. <title>Edit Contents</title>
  6. <link type="text/css" rel="stylesheet" media="all" href="/site/site.css" />
  7. <script type="text/javascript" src="/site/editor/jscripts/tiny_mce/tiny_mce.js"></script>
  8. <script type="text/javascript">
  9. tinyMCE.init({
  10. // General options
  11. mode : "textareas",
  12. theme : "advanced",
  13. 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, ibrowser",
  14.  
  15. // Theme options
  16. theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
  17. 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",
  18. theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
  19. theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage, ibrowser",
  20. theme_advanced_toolbar_location : "top",
  21. theme_advanced_toolbar_align : "left",
  22. theme_advanced_statusbar_location : "bottom",
  23. theme_advanced_resizing : true,
  24.  
  25. // Example content CSS (should be your site CSS)
  26. content_css : "css/example.css",
  27.  
  28. // Drop lists for link/image/media/template dialogs
  29. template_external_list_url : "js/template_list.js",
  30. external_link_list_url : "js/link_list.js",
  31. external_image_list_url : "js/image_list.js",
  32. media_external_list_url : "js/media_list.js",
  33.  
  34. // Replace values for the template plugin
  35. template_replace_values : {
  36. username : "Some User",
  37. staffid : "991234"
  38. }
  39. });
  40. </script>
  41. </head>
  42. <body>
  43. <br />
  44.  
  45. <form method="post" action="/site/insert.php">
  46. <label for="title"><b> Article Title:</b></label><br />
  47. <input name="heading" id="title" type="text" maxlength="150" />
  48. <br /> <br />
  49. <div style="width:100%; height:100%; ">
  50. <label for="title"><b>Article Message:</b></label><br />
  51. <textarea name="contents" style="width:100%; height:400px; ">
  52. </textarea>
  53. <br />
  54. <INPUT type="submit" value="Save"/>
  55.  
  56. </form>
  57. </div>
  58. <?php
  59. # Using SCRIPT_NAME
  60.  
  61. //$path = $_SERVER['SCRIPT_NAME'];
  62.  
  63. //echo "Path To Script Example: <a href='$path'>An Article Title</a>";
  64.  
  65. ?>
  66. </body>
  67. </html>
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
---- Python, C++ PHP and Java ----
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster
 
-1
  #2
Oct 6th, 2009
Pretty simple. Fetch the data from the database and place it between <textarea> tags. Here is an example.
  1. <?php
  2. if(isset($_POST['save'])) {
  3. print "<pre>";
  4. print_r($_POST);
  5. print "</pre>";
  6. }
  7. ?>
  8. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  9. <html xmlns="http://www.w3.org/1999/xhtml">
  10. <head>
  11. <title>Full featured example</title>
  12.  
  13. <!-- TinyMCE -->
  14. <script type="text/javascript" src="../jscripts/tiny_mce/tiny_mce.js"></script>
  15. <script type="text/javascript">
  16. tinyMCE.init({
  17. // General options
  18. mode : "textareas",
  19. theme : "advanced",
  20. plugins : "safari,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,wordcount",
  21.  
  22. // Theme options
  23. theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
  24. 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",
  25. theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
  26. theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
  27. theme_advanced_toolbar_location : "top",
  28. theme_advanced_toolbar_align : "left",
  29. theme_advanced_statusbar_location : "bottom",
  30. theme_advanced_resizing : true,
  31.  
  32. // Example content CSS (should be your site CSS)
  33. content_css : "css/content.css",
  34.  
  35. // Drop lists for link/image/media/template dialogs
  36. template_external_list_url : "lists/template_list.js",
  37. external_link_list_url : "lists/link_list.js",
  38. external_image_list_url : "lists/image_list.js",
  39. media_external_list_url : "lists/media_list.js",
  40.  
  41. // Replace values for the template plugin
  42. template_replace_values : {
  43. username : "Some User",
  44. staffid : "991234"
  45. }
  46. });
  47. </script>
  48. <!-- /TinyMCE -->
  49.  
  50. </head>
  51. <body>
  52.  
  53. <form method="post" action="live_example.php">
  54. <div>
  55. <h3>Full featured example</h3>
  56.  
  57. <p>
  58. This page shows all available buttons and plugins that are included in the TinyMCE core package.
  59. There are more examples on how to use TinyMCE in the <a href="http://wiki.moxiecode.com/examples/tinymce/">Wiki</a>.
  60. </p>
  61.  
  62. <!-- Gets replaced with TinyMCE, remember HTML in a textarea should be encoded -->
  63. <div>
  64. <textarea id="elm1" name="elm1" rows="15" cols="80" style="width: 80%">
  65. <?php
  66. $con = mysql_connect("localhost","root");
  67. mysql_select_db("test_cms");
  68. $query = "SELECT * FROM category where ct_id=1";
  69. $result = mysql_query($query);
  70. $row = mysql_fetch_assoc($result);
  71. $contents = $row['ct_description'];
  72. echo $contents;
  73. ?>
  74. </textarea>
  75. </div>
  76.  
  77. <!-- Some integration calls -->
  78. <a href="javascript:;" onmousedown="tinyMCE.get('elm1').show();">[Show]</a>
  79. <a href="javascript:;" onmousedown="tinyMCE.get('elm1').hide();">[Hide]</a>
  80. <a href="javascript:;" onmousedown="tinyMCE.get('elm1').execCommand('Bold');">[Bold]</a>
  81. <a href="javascript:;" onmousedown="alert(tinyMCE.get('elm1').getContent());">[Get contents]</a>
  82. <a href="javascript:;" onmousedown="alert(tinyMCE.get('elm1').selection.getContent());">[Get selected HTML]</a>
  83. <a href="javascript:;" onmousedown="alert(tinyMCE.get('elm1').selection.getContent({format : 'text'}));">[Get selected text]</a>
  84. <a href="javascript:;" onmousedown="alert(tinyMCE.get('elm1').selection.getNode().nodeName);">[Get selected element]</a>
  85. <a href="javascript:;" onmousedown="tinyMCE.execCommand('mceInsertContent',false,'<b>Hello world!!</b>');">[Insert HTML]</a>
  86. <a href="javascript:;" onmousedown="tinyMCE.execCommand('mceReplaceContent',false,'<b>{$selection}</b>');">[Replace selection]</a>
  87.  
  88. <br />
  89. <input type="submit" name="save" value="Submit" />
  90. <input type="reset" name="reset" value="Reset" />
  91. </div>
  92. </form>
  93.  
  94. </body>
  95. </html>
I have placed this file in the examples folder of tiny_mce. Don't forget to change username, dbname, etc.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,474
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 128
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Nearly a Posting Virtuoso
 
0
  #3
Oct 6th, 2009
changed to ckeditor which allowed me to use two different textareas
Now I will be able to get both inputs.
Also it have nice image uploader as ibrowser have some issues of deprecated eregi() function

Thanks alot for the help!
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
---- Python, C++ PHP and Java ----
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster
 
-1
  #4
Oct 6th, 2009
ckeditor ? Hmm.. Haven't tried it. Anyways, goodluck man. Cheers!
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,474
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 128
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Nearly a Posting Virtuoso
 
0
  #5
Oct 11th, 2009
Originally Posted by nav33n View Post
ckeditor ? Hmm.. Haven't tried it. Anyways, goodluck man. Cheers!
OOops! That beautiful image uploader isn't there in latest version (ckeditor) and they say until version 3.1? Very bad!

Now can anyone help me up and running on how to make image uploader?
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
---- Python, C++ PHP and Java ----
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum


Views: 888 | Replies: 4
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC