Jump to content

Recommended Posts

Hello all

 

I have installed FCKEditor onto a site I have put together but am struggling to get the post to update if they want to make any changes

 

I have the following code

 

if ($_POST['submit_form'] == 1)  { 
    // Save to the database 
    $data = mysql_real_escape_string(trim($_POST['fcktext']));
$post_id = ($_POST['post_id']);
$intro = substr ($data,0,100); 
$res = mysql_query("UPDATE `posts` SET post = '".$data."' WHERE post_id ='".$post_id."'"); 
     
    if (!$res) 
      die("Error saving the record!  Mysql said: ".mysql_error()); 
     
    // Redirect to self to get rid of the POST 
    header("Location: index.php"); 
  } 

  include_once "includes/fckeditor/fckeditor.php";
  ?>

Can anyone spot any errors in the code?

Cheers

Mark
[/code

Link to comment
https://forums.phpfreaks.com/topic/118672-solved-fck-editor/
Share on other sites

Hello

 

I have ot part of it cracked, but am now getting an error message of Parse error: syntax error, unexpected '[' in /home/fhlinux144/g/gavstersays.co.uk/user/htdocs/admin/edit_post.php on line 12

 

The entire code page is

<?php 
  
  // Connect to the database 
  $cnx = mysql_connect('IP', 'user', 'pword') 
         OR die("Unable to connect to database!"); 
  mysql_select_db('d_base', $cnx); 
   
   
  if ($_POST['submit_form'] == 1)  { 
    // Save to the database 
    $data = mysql_real_escape_string(trim($_POST['fcktext'])); 
$topic = ($_POST['topic']);
$title = ($_POST['title']);
$intro = substr ($data,0,100);
    $res = mysql_query("INSERT INTO posts (topic_id, post, title,intro) VALUES('$topic','$data','$title','$intro')");

     
    if (!$res) 
      die("Error saving the record!  Mysql said: ".mysql_error()); 
     
    // Redirect to self to get rid of the POST 
    header("Location: index.php"); 
  }
  include_once "includes/fckeditor/fckeditor.php"; 
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/gavsteradmin.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Gavster Says | MC Gavster The Lyrical Gangsta</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<link href="../style/gavster.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div align="center">
<div style="width:850px; border:2px solid #0066FF; background-color:#3366FF">
<div id="header">
  <div id="head"></div>
</div>
<div id="topics">
  <h2>Admin</h2>
  <ul style="list-style:none; text-align:left"><li><a href="add_post.php">Add a post</a></li>
  <li><a href="add_topic.php">Add a Topic</a></li>
  </ul>
  <div align="left">

  </div>
</div>
<div id="maintext"><!-- InstanceBeginEditable name="maintext" -->
<form action="add_post.php" method="post">
<table>
<?php
echo ('<tr><td><select name="topic" class="button">');
$con = mysql_connect('host', 'user', 'pword', true);
if(!$con)
{
      die('Could not connect: ' . mysql_error());
}
mysql_select_db('dbname', $con);
$result = mysql_query('SELECT * FROM `topics`', $con) or die(mysql_error());
if(mysql_num_rows($result) < 1) 
echo('<option>there is no data in table..</option>');
else
{
while($row=mysql_fetch_assoc($result))
{
echo('<option value='.$row[topic_id].'>'.$row[topic].'</option>');
}
}
echo ('</select></td></tr>');

?>
<tr><td><input name="title" type="text" value="Enter Title of Post Here..." size="70" class="button"/></td></tr>
<?php 
echo ('<tr><td>');
  $oFCKeditor = new FCKeditor('fcktext'); 
  $oFCKeditor->BasePath = "includes/fckeditor/"; 
  $oFCKeditor->Value    = ""; 
  $oFCKeditor->Width    = 540; 
  $oFCKeditor->Height   = 400; 
  echo $oFCKeditor->CreateHtml(); 
echo ('</td></tr>');
?>
<br /> 
<tr><td><input type="hidden" name="submit_form" value="1" /> </td></tr>
<tr><td><input type="submit" value="Save Post" class="button"/> </td></tr>
</table>
</form>
<!-- InstanceEndEditable --></div>
<div id="credit">design by <a href="http://www.bravo14.co.uk" target="_blank">bravo14</a></div>
<div id="copyright">© Gavin Netherton</div>
</div>
</div>
</body>
<!-- InstanceEnd --></html>
<?php  
  // Close the database connection 
  mysql_close($cnx); 
?>

Link to comment
https://forums.phpfreaks.com/topic/118672-solved-fck-editor/#findComment-611144
Share on other sites

I have installed FCKEditor on a website I have put together, I have been able to insert a post into MySQL from the editor, but I can't seem to get the post to update, I have used the code below

 

<?php  
   
  // Connect to the database 
  $cnx = mysql_connect('IP', 'user', 'password') 
         OR die("Unable to connect to database!"); 
  mysql_select_db('dbname', $cnx); 
   
   
  if ($_POST['submit_form'] == 1)  { 
    // Save to the database 
    $data = mysql_real_escape_string(trim($_POST['fcktext']));
$post_id = ($_POST['post_id']);
$intro = substr ($data,0,100); 
$res = mysql_query("UPDATE `posts` SET post = '".$data."' WHERE post_id =".$post_id.""); 
     
    if (!$res) 
      die("Error saving the record!  Mysql said: ".mysql_error()); 
     
    // Redirect to self to get rid of the POST 
    header("Location: index.php"); 
  } 

  include_once "includes/fckeditor/fckeditor.php";
  ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/gavsteradmin.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Gavster Says | MC Gavster The Lyrical Gangsta</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<link href="../style/gavster.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div align="center">
<div style="width:850px; border:2px solid #0066FF; background-color:#3366FF">
<div id="header">
  <div id="head"></div>
</div>
<div id="topics">
  <h2>Admin</h2>
  <ul style="list-style:none; text-align:left"><li><a href="add_post.php">Add a post</a></li>
  <li><a href="add_topic.php">Add a Topic</a></li>
  </ul>
  <div align="left">

  </div>
</div>
<div id="maintext"><!-- InstanceBeginEditable name="maintext" -->
<form action="edit_post.php" method="post">
<?php  
  // Get data from the database 
  $query = mysql_query('SELECT * FROM `posts`where `post_id`=\'' . $_GET['post_id'] . '\''); 
  $row = mysql_fetch_array($query); 

  //other fields within post
  echo ('<input name="title" type="text" value="'.$row[title].'" width="50" readonly="true"/>');
  echo('<input name="post_id" type="hidden" value="'.$row[post_id].'"/>');
  // Configure and output editor 
  $oFCKeditor = new FCKeditor('fcktext'); 
  $oFCKeditor->BasePath = "includes/fckeditor/"; 
  $oFCKeditor->Value    = $row["post"]; 
  $oFCKeditor->Width    = 540; 
  $oFCKeditor->Height   = 400; 
  echo $oFCKeditor->CreateHtml(); 
?> 
<br /> 
<input type="hidden" name="submit_form" value="1" /> 
<input type="submit" value="Save Post" class="button"/> 
</form>

<!-- InstanceEndEditable --></div>
<div id="credit">design by <a href="http://www.bravo14.co.uk" target="_blank">bravo14</a></div>
<div id="copyright">© Gavin Netherton</div>
</div>
</div>
</body>
<!-- InstanceEnd --></html>
<?php  
  // Close the database connection 
  mysql_close($cnx); 
?>

 

I don't get an error message, but the entry in the database doesn't update.

 

Any help would be appreciated

Link to comment
https://forums.phpfreaks.com/topic/118672-solved-fck-editor/#findComment-611346
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.