Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP FCKeditor and updating data to MySQL Database

Posted on 2008-06-23
9
Medium Priority
?
2,067 Views
Last Modified: 2010-06-08
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
Comment
Question by:Ryan Bayne
  • 6
  • 3
9 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 21844940
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
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 2000 total points
ID: 21844973
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
 
LVL 2

Author Comment

by:Ryan Bayne
ID: 21850997
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Author Comment

by:Ryan Bayne
ID: 21851062
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
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 2000 total points
ID: 21856752
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
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 2000 total points
ID: 21856801
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
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 21857045
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
 
LVL 2

Author Comment

by:Ryan Bayne
ID: 21858451
     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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 21858732
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

Featured Post

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.

Question has a verified solution.

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

By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

963 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