Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2110
  • Last Modified:

PHP FCKeditor and updating data to MySQL Database

Hey

Theres a lot of discussion already online about this editor and a very good tutorial...

http://www.msbware.com/articles/php/integrating_fckeditor_with_your_mysql_database.html

but I cant seem to get anything I edit to store to database. I submit and the page returns to where its meant to as if the query has been done. I have a similiar process with another button on the same page as it is an admin page and that works. So I'm sure I know up to UPDAte to database. I can only suspect its passing the data from one page to another but I've tried everything even hidden fields.

 I'll show you where I'm at hopefully someone spots something easy.

Thanks
This is the line in the database query, its under similair lines which work fine so the query is fine...
 
	$text = $row['script'];
 
This is the line that holds the value of data displayed in the editor. It shows correctly what is in my DB...
 
$oFCKeditor->Value = $text["script"] ;
 
(I've also tried $text['text'] but at the moment since doing that the data in the db is erased, black so I imagine the variable value is just that but I cant seem to sort it and pass a value.
 
I done this accidently 							script = '$$postedValue'
and the database is populated with  $

Open in new window

0
Ryan Bayne
Asked:
Ryan Bayne
  • 6
  • 3
4 Solutions
 
Ray PaseurCommented:
TycoonMillion:

This statement: $text = $row['script']; tells PHP to take the associative array named $row, locate the element named 'script' and put that value into the variable named $text.

Almost certainly the 'script' is a scalar variable, therefore the $text variable will be a scalar variable, not an array.

This statment: $oFCKeditor->Value = $text["script"] ; assumes that $text is an array.

Does that help isolate the issue? ~Ray
0
 
Ray PaseurCommented:
Also, I read the tut at http://www.msbware.com/articles/php/integrating_fckeditor_with_your_mysql_database.html

If you want to post your code that implements that tutorial (put it in clear text in the code snippet) I will be glad to look it over.  I've never implemented FCKEditor, but I have plenty of experience with TinyMCE (the wordpress engine) and I'm sure the two editors have much in common.

Standing by, ~Ray
0
 
Ryan BayneWordPress DeveloperAuthor Commented:
Well I figured its mostly to do with this line...

$oFCKeditor->Value = $text["script"] ;  and recently realised its causing this error..

Notice: Uninitialized string offset: 0 in C:\AppServ\www\WTG2008\httpdocs\Inc\tutorialedit.php on line 69

Been trying to sort it but no luck. Either end up with all the expected data in the form but doesnt update to the database or end up with just the first character or something.

Any ideas?

0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Ryan BayneWordPress DeveloperAuthor Commented:
Heres my script too, its more broken up to suit my needs but I'll make it clear as I can. I have spent a lot of time trying many different things to get it working so might be different from the original downloaded script.

Thanks for your time already
First I call these in tutorials.php
 
include 'inc/tutorialedit.php'; //For editing DB data related to tutorials
include 'wysiwyg/fckeditor.php'; //Establish required WYSIWYG PHP version php4 or php5
---------------------------------------------------------------------
 
 
Second is tutorialedit.php (using this editor for tutorials), this holds my own form fields which work fine, then the code already mentioned belonging to the editor.
 
<?php
	include 'wysiwyg/fckeditor.php'; //Establish required WYSIWYG PHP version php4 or php5
			
DB CONN DETAILS REMOVED	
	mysql_connect("$host", "$user", "$password")or die("cannot connect");
	mysql_select_db("$database")or die("cannot select DB");
 
$result = mysql_query("SELECT * FROM tutorials");
if (!$result) {
    die('Query execution problem: ' . mysql_error());
}
 
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    //Put all array data results into variables for display in form
	$tutid = $row['id'];
	$tuttitle = $row['title'];
	$subone = $row['subjectone'];
	$subtwo = $row['subjecttwo'];
	$ratername = $row['ratername'];
	$text = $row['script'];
}
 
mysql_free_result($result);
?>
 
  <form name="tutorialdetails" id="tutorialdetails" method="post" action="process/tutorialupdate.php">
    <table>
	
      <tr>
        <th scope="row" class="leftLabel">ID </th>
        <td><input name="tutid" type="text" class="mediumbox" id="tutid" value="<?php echo $tutid; ?>" size="30" maxlength="20"	/></td>
      </tr>
	  
	  <tr>
        <th scope="row" class="leftLabel">Title </th>
        <td><input name="tuttitle" type="text" class="mediumbox" id="tuttitle" value="<?php echo $tuttitle; ?>" size="30" maxlength="20"	/>        </td>
      </tr>
	  
	  <tr>
        <th scope="row" class="leftLabel">Primary Subject </th>
        <td><input name="subone" type="text" class="mediumbox" id="subone" 	value="<?php echo $subone; ?>" size="30" maxlength="20"	/></td>
      </tr>
	  
	  <tr>
        <th scope="row" class="leftLabel">Secondary Subject</th>
        <td><input name="subtwo" type="text" class="mediumbox" id="subtwo" 	value="<?php echo $subtwo; ?>" size="30" maxlength="20"	/></td>
      </tr>
	  
	  <tr>
        <th scope="row" class="leftLabel">Rater Name</th>
        <td><input name="ratername" type="text" class="mediumbox" id="ratername" 	value="<?php echo $ratername; ?>" size="30" maxlength="20"	/></td>
      </tr>
	  
      <tr>
        <th colspan="3">		<div align="center">
          <?php
// Automatically calculates the editor base path based on the _samples directory.
// This is usefull only for these samples. A real application should use something like this:
// $oFCKeditor->BasePath = '/fckeditor/' ;	// '/fckeditor/' is the default value.
$sBasePath = $_SERVER['PHP_SELF'] ;
$sBasePath = substr( $sBasePath, 0, strpos( $sBasePath, "_samples" ) ) ;
 
$oFCKeditor = new FCKeditor('FCKeditor1') ;
$oFCKeditor->BasePath	= $sBasePath ;
$oFCKeditor->Value		= $text["script"] ;
  $oFCKeditor->Width    = 600 ;
  $oFCKeditor->Height   = 250 ; 
$oFCKeditor->Create() ;
?>
          <input name="updatetutorial" type="submit" id="updatetutorial" value="Update Tutorial" />
        </div></th>
      </tr>
    </table>
  </form>
-------------------------------------------------------------------
 
Third is Tutorialupdate.php called by the form and should update the DB then forward user to the tutorials.php home page. 
 
 
	mysql_connect("$host", "$user", "$password")or die("cannot connect");
	mysql_select_db("$database")or die("cannot select DB");
 
	$tutid = $_POST['tutid'];
 
$result = mysql_query("UPDATE tutorials SET 
							title = '$tuttitle', 
							subjectone = '$subone',
							subjecttwo = '$subtwo',
							ratername = '$ratername',
							script = '$script'
					   WHERE id = '$tutid'");
//Send to a location depending on outcome of the query						 
if (!$result) {
    die('Query execution problem: ' . mysql_error());
}
else
{
header("location:/wtg2008/httpdocs/index.php?cellname=pagecells/admin/tutorials.php");
exit();
}

Open in new window

0
 
Ray PaseurCommented:
TM: I may have a couple of posts here, but I'll tell you what I'm seeing as I work through this code.

First of all, this segment of code selects all the records from the table, iterates over the table until it gets to the last record and the variables are assigned for only the last record.  Since there was no ORDER BY in the SELECT statement, the order of the output (ie: which one was last) is unpredictable.
$result = mysql_query("SELECT * FROM tutorials");
if (!$result) {
    die('Query execution problem: ' . mysql_error());
}
 
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    //Put all array data results into variables for display in form
        $tutid = $row['id'];
        $tuttitle = $row['title'];
        $subone = $row['subjectone'];
        $subtwo = $row['subjecttwo'];
        $ratername = $row['ratername'];
        $text = $row['script'];
}
 
mysql_free_result($result);
?>

Open in new window

0
 
Ray PaseurCommented:
The first  line of code (near line 29 in your post) assigns a scalar value to the variable $text.

The second line of code (near line 74 in your post) treats the variable $text as if it is an associative array.

Clearly $text can be one or the other, but not both.  Possibly you want something like the third line of code in line 74.
$text = $row['script'];
 
$oFCKeditor->Value              = $text["script"] ;
 
$oFCKeditor->Value              = $text ;

Open in new window

0
 
Ray PaseurCommented:
In the third script, place the following lines right after the mysql_select_db (near line 90). This will print out the values in $_POST - that is the information being transferred to the third script.  You will be able to see the variable names and values.

Also, it looks like your script assumes that register_globals is ON.  You should run phpinfo(); and determine whether is on or off.  Please do that and post back the results of var_dump and phpinfo.
echo "<pre>;
var_dump($_POST);
echo "</pre>";

Open in new window

0
 
Ryan BayneWordPress DeveloperAuthor Commented:
     echo var_dump($_POST);  alone worked, thanks for that will need to use that more often.

FCKeditor1 is the variable name that should be used in the UPDATE query.

As for global_variables thats something I'm going to study up on because I keep getting told about it but I can never seem to avoid it when I'm coding.

Cheers for the help I learned a bundle over this.
UPDATE tutorials SET 
                                                        title = '$tuttitle', 
                                                        subjectone = '$subone',
                                                        subjecttwo = '$subtwo',
                                                        ratername = '$ratername',
                                                        script = '$FCKeditor1'
                                           WHERE id = '$tutid'"

Open in new window

0
 
Ray PaseurCommented:
Glad you're on the right track!  Look out for register_globals.  It is deprecated, and OFF is the preferred value now.

Good luck going forward, ~Ray
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now