Solved

PHP FCKeditor and updating data to MySQL Database

Posted on 2008-06-23
9
1,957 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 108

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 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 500 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 500 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 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 500 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 108

Accepted Solution

by:
Ray Paseur earned 500 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 108

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now