Jump to content

Ckeditor With Php And Mysql


tehjagjr

Recommended Posts

Hi guys, ive got an awkward problem that doesn't seem to want to fix itself no matter how hard i try.

 

Basically,

 

I have in my Database a table called horses and the columns are

 

 

 

I then have a php webpage with a dropdown box which is populated from the database.

 

<form action="" method="post" align="center">
   <fieldset>  
   <select name="horses" onchange="benSucksDick(this.value)" align="center">  
       <option value="">Select a Horse</option><Br><br><br>
       <!-- RUN QUERY TO POPULATE DROP DOWN --> 
       <?php 
 mysql_connect("localhost", "root", "") or die("Connection Failed");
mysql_select_db("horse")or die("Connection Failed");
       $query = "SELECT * FROM horses ORDER by ID";  
       $result = mysql_query($query) or die(mysql_error()); 
       /*$num = mysql_num_rows($result);*/  
       while($row = mysql_fetch_array($result)) {   
           echo "<option value='".$row['ID']."'>".$row['Name']."</option>"; 
       } 
       ?>                             
   </select></fieldset>  

 

I also have a AJAX call to edit.php which fetches the data in column web_horse and outputs it to a CKeditor instance.

 

AJAX code

<script type="text/javascript">
function benSucksDick(str)
{
if (str=="")
  {
  document.getElementById("maincontent").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
 {
 document.getElementById("maincontent").innerHTML=xmlhttp.responseText;
 }
  }
xmlhttp.open("GET","content/edit.php?q="+str,true);
xmlhttp.send();
}
</script>

 

edit.php Code

<?php
error_reporting(-1);
// Make sure you are using a correct path here.
include 'ckeditor/ckeditor.php';


$ckeditor = new CKEditor();
$ckeditor->basePath = '/ckeditor/';
$ckeditor->config['filebrowserBrowseUrl'] = '/ckfinder/ckfinder.html';
$ckeditor->config['filebrowserImageBrowseUrl'] = '/ckfinder/ckfinder.html?type=Images';
$ckeditor->config['filebrowserFlashBrowseUrl'] = '/ckfinder/ckfinder.html?type=Flash';
$ckeditor->config['filebrowserUploadUrl'] = '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files';
$ckeditor->config['filebrowserImageUploadUrl'] = '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images';
$ckeditor->config['filebrowserFlashUploadUrl'] = '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash';


mysql_connect("localhost", "root", "") or die("Connection Failed");
mysql_select_db("horse")or die("Connection Failed");
$q=$_GET["q"];
$sql="SELECT web_content FROM horses WHERE id = '".$q."'";
$resultab = mysql_query($sql);
while($row = mysql_fetch_array($resultab))
 {
 echo $row['web_content'];
 }
?>

 

Now, the CKeditor initialises when the page is loaded, but when i change the dropdown to a different value from the database it just shows the html code and/or a text area WITHOUT the CKeditor instance.

 

If anyone can help me, that would be grand!!

post-132992-0-65531300-1351102830_thumb.png

Link to comment
https://forums.phpfreaks.com/topic/269866-ckeditor-with-php-and-mysql/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.