I have the PHP FCKeditor within a form posting to a MySQL database. Both the editor and the connection are working, however when I hit submit, the data is not being saved.
You can try it out here:
http://66.118.157.72/editor/editor.php
Please take a look at the code below and tell me what I'm missing, thanks:
<?php require_once('../connections/fbf.php'); ?>
<?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "decimal": $theValue = ($theValue != "") ? floatval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } $editFormAction = $HTTP_SERVER_VARS['PHP_SELF']; if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) { $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING']; } if ((isset($HTTP_POST_VARS["fbf_update"])) && ($HTTP_POST_VARS["fbf_update"] == "form1")) { $updateSQL = sprintf("UPDATE que_content SET entry=%s WHERE id_number=%s", GetSQLValueString($HTTP_POST_VARS['entry'], "text"), GetSQLValueString($HTTP_POST_VARS['id_number'], "int")); mysql_select_db($database_fbf, $flawlor); $Result1 = mysql_query($updateSQL, $flawlor) or die(mysql_error()); $updateGoTo = "final.php"; if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) { // $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $HTTP_SERVER_VARS['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo)); } mysql_select_db($database_fbf, $flawlor); $query_Recordset1 = "SELECT id_number, entry FROM que_content WHERE id_number=1"; $Recordset1 = mysql_query($query_Recordset1, $flawlor) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); include("../fckeditor/fckeditor.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" >
<head>
<title>Content Management System</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<link href="sample.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function FCKeditor_OnComplete( editorInstance )
{
var oCombo = document.getElementById( 'cmbToolbars' ) ;
oCombo.value = editorInstance.ToolbarSet.Name ;
oCombo.style.visibility = '' ;
}
function ChangeToolbar( toolbarName )
{
window.location.href = window.location.pathname + "?Toolbar=" + toolbarName ;
}
</script>
</head>
<body>
<div id="pagewidth" >
<div id="header" >
<div id="navholder">
</div>
</div>
<div id="outer" >
<div id="inner">
<div id="maincol">
<div id="leftcol">
</div>
<!-- CENTER COLUMN BEGINS -->
<div id="centercol">
<h2>Content Management System</h2>
<div id="admin">
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<p id="editor">
<label>Homepage text</label><br />
<?php $oFCKeditor = new FCKeditor('form1') ; $oFCKeditor->BasePath = '../fckeditor/' ; if ( isset($_GET['Toolbar']) ) $oFCKeditor->ToolbarSet = $_GET['Toolbar'] ; $oFCKeditor->Value = $row_Recordset1['entry'] ; $oFCKeditor->Create() ; ?>
<input type="submit" value="Submit" />
<input type="hidden" name="fbf_update" value="form1">
<input type="hidden" name="id_number" value="<?php echo $row_Recordset1['id_number']; ?>">
</p>
</form>
</div>
<div id="rightcol">
</div>
<!-- /// FOOTER STARTS /// -->
<div id="footer">
<p>
Footer </p>
</div>
<!-- /// FOOTER ENDS /// -->
<!-- below div closes maincol -->
</div>
<div class="clr"></div>
<!-- close inner and outer -->
</div>
</div>
</div>
</body>
</html>
<?php mysql_free_result($Recordset1); ?>
RE: PHP/MySQL: Problems posting input to data
The standard dreamweaver update recordset doesn't work with the editor. I had the same problem. The problem is the getthesqlvalue function; it just fubarrs the sql it generates and mysql doesn't understand it.
First, delete the getthesqlvalue function entirely. Be sure you get it all from the opening curly bracket to the last.
Then change this:
if ((isset($HTTP_POST_VARS["fbf_update"])) && ($HTTP_POST_VARS["fbf_update"] == "form1")) {
$updateSQL = sprintf("UPDATE que_content SET entry=%s WHERE id_number=%s",
GetSQLValueString($HTTP_POST_VARS['entry'], "text"),
GetSQLValueString($HTTP_POST_VARS['id_number'], "int"));
To this:
if ((isset($HTTP_POST_VARS["fbf_update"])) && ($HTTP_POST_VARS["fbf_update"] == "form1")) {
$entryVar = $HTTP_POST_VARS['entry'];
$idVar = $HTTP_POST_VARS['id_number'];
$updateSQL = "UPDATE que_content SET entry = '".$entryVar."' WHERE id_number = ".$idVar;
RE: PHP/MySQL: Problems posting input to data
Thanks for the help, meth. I tried your suggestion, and I'm still getting the same result of no data being posted to the database. I don't have to use the Dreamweaver cms syntax, I just need a php/mysql version that works with fckeditor.
Here's the latest version:
http://66.118.157.72/editor/editor2.php
Here's the code:
<?php require_once('../connections/fbf.php'); ?>
<?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if ((isset($HTTP_POST_VARS["fbf_update"])) && ($HTTP_POST_VARS["fbf_update"] == "form1")) { $entryVar = $HTTP_POST_VARS['entry']; $idVar = $HTTP_POST_VARS['id_number']; $updateSQL = "UPDATE que_content SET entry = '".$entryVar."' WHERE id_number = ".$idVar; } } mysql_select_db($database_fbf, $flawlor); $query_Recordset1 = "SELECT id_number, entry FROM que_content WHERE id_number=1"; $Recordset1 = mysql_query($query_Recordset1, $flawlor) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); include("../fckeditor/fckeditor.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"; >
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en" >
<head>
<title>Content Management System</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<link href="sample.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function FCKeditor_OnComplete( editorInstance )
{
var oCombo = document.getElementById( 'cmbToolbars' ) ;
oCombo.value = editorInstance.ToolbarSet.Name ;
oCombo.style.visibility = '' ;
}
function ChangeToolbar( toolbarName )
{
window.location.href = window.location.pathname + "?Toolbar=" + toolbarName ;
}
</script>
</head>
<body>
<div id="pagewidth" >
<div id="header" >
<div id="navholder">
</div>
</div>
<div id="outer" >
<div id="inner">
<div id="maincol">
<div id="leftcol">
</div>
<!-- CENTER COLUMN BEGINS -->
<div id="centercol">
<h2>Content Management System</h2>
<div id="admin">
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<p id="editor">
<label>Homepage text</label><br />
<?php $oFCKeditor = new FCKeditor('form1') ; $oFCKeditor->BasePath = '../fckeditor/' ; if ( isset($_GET['Toolbar']) ) $oFCKeditor->ToolbarSet = $_GET['Toolbar'] ; $oFCKeditor->Value = $row_Recordset1['entry'] ; $oFCKeditor->Create() ; ?>
<input type="submit" value="Submit" />
<input type="hidden" name="fbf_update" value="form1">
<input type="hidden" name="id_number" value="<?php echo $row_Recordset1['id_number']; ?>">
</p>
</form>
</div>
<div id="rightcol">
</div>
<!-- /// FOOTER STARTS /// -->
<div id="footer">
<p>
Footer </p>
</div>
<!-- /// FOOTER ENDS /// -->
<!-- below div closes maincol -->
</div>
<div class="clr"></div>
<!-- close inner and outer -->
</div>
</div>
</div>
</body>
</html>
<?php mysql_free_result($Recordset1); ?>
RE: PHP/MySQL: Problems posting input to data
I think I spotted the problem; you have instantiated the fckeditor as "form1";
$oFCKeditor = new FCKeditor('form1')
The editor will post the value of the edited content as $_POST ['form1'], same name as what you instantiate it. Instead you are grabbing the value from a different field;
$entryVar = $HTTP_POST_VARS['entry'];
This input value isn't even present in your form.
Your form also has the same name as your fck instance. Either change the form name and update:
<input type="hidden" name="fbf_update" value="form1">
to reflect this, or change the FCKeditor instance name, and edit your sql string & vars to reflect that change.
RE: PHP/MySQL: Problems posting input to data