Ryan Bayne
asked on
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
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 $
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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\htt pdocs\Inc\ tutorialed it.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?
$oFCKeditor->Value = $text["script"] ; and recently realised its causing this error..
Notice: Uninitialized string offset: 0 in C:\AppServ\www\WTG2008\htt
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?
ASKER
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
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();
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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'"
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
Good luck going forward, ~Ray
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