Hi I am working on updating content with fckeditor page
I am facing problem when i add new page in the addnewpage.php and return to index screen my data is not kept
the following is my index.php
<?php
session_start();
include 'getconnect.php';
include("FCKeditor/fckeditor.php") ;
?>
<?php
if(isset($_GET['action'])== 'update')
{//print_r($_REQUEST);die;
$a=$_POST['FCKeditor1'];
$b=strlen($a);
if($b==13 || $b ==0)
{
header("Location: index.php?fileid=".$_GET['id']);
exit();
}
$value=addslashes($_POST['FCKeditor1']);
$data=htmlspecialchars($value);
$queryUpdatecms = "update tempcms set ";
$queryUpdatecms .="tempcontent = '".$data."'";
$queryUpdatecms .= " where tempfileid =".$_GET['fileid'];
$result=mysql_query($queryUpdatecms);
if(!$result)
{
$_SESSION['message'] = mysql_error();
header("Location:index.php");
exit();
}
else
{
$_SESSION['message']="Record Updated Successfully";
header("Location:index.php");
exit();
}
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>CMS </title>
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {font-size: 12px}
.style6 {color: #FF0000}
-->
</style>
</head>
<body>
<?php
if(isset($_GET['module']) && ($_GET['module'] =='get')) {?>
<form name="news" method="post" action="index.php?action=update&fileid=<?php echo $_GET['id'];?>" >
<?php } else if(!isset($_GET['module']) || ($_GET['module']=='')){ ?>
<form name="news" method="post" action="FCKeditor/_samples/php/sampleposteddata.php">
<?php } ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="top"> </td>
</tr>
<tr>
<td align="left" valign="top" class="toptablebackbround"></td>
</tr>
<tr>
<td align="left" valign="top" class="tablebackgroundwhite">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="240" align="center" valign="top">
<?php
include("left.php"); ?></td>
<td align="left" valign="top">
<table>
<tr>
<td><font color="#FF0000">
<?php if(isset($_GET['module']) && $_GET['module']=='insert'){echo "New Record Added Succesfully";}?>
<?php if(!empty($_SESSION['message'])) echo $_SESSION['message']; $_SESSION['message'] = ''; ?></font>
</td>
</tr>
<tr>
<td><?php
if(isset($_GET['module']) && $_GET['module']=='get') {
$getqry="select * from tempcms where tempfileid=".$_GET['id'];
$res=mysql_query($getqry);
$row=mysql_fetch_row($res);
$editor=$row[2];
$returncontent=stripslashes($editor);
$content1=strtr($returncontent, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
$print=$content1;
//echo $print;
//die;
}
?>
</table>
<table cellSpacing=0 cellPadding=0 width="100%" border=0>
<tr>
<td align="left" colspan="8" class="InputText"> <STRONG>Content<?php echo $row[1]; ?></STRONG></td>
</tr>
<tr>
<td colspan="5" >
<?php
$oFCKeditor = new FCKeditor('FCKeditor1') ;
$oFCKeditor->BasePath = 'FCKeditor/';
if(isset($_GET['module'])== 'get')
{
$oFCKeditor->Value =$print;
}
else
{
$oFCKeditor->Value ='';
}
$oFCKeditor->Create();
?> </td>
</tr>
<tr><td colspan="7"> </td></tr>
<tr>
<td colspan="5" align="center">
<?php if(isset($_GET['module'])== 'get')
{
?>
<input type="submit" name="Update" value="Update">
<?php
}
else{
?>
<input name="Submit" type="submit" value="Submit">
<?php
}
?>
</td>
</tr>
</table></td>
<td width="20" align="left" valign="top"> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="left" valign="top" colspan=6 class="bottomtablebackbround"></td>
</tr>
<tr>
<td height="25" align="left" valign="bottom"><a href="addnewpage.php">Add New Page</a></td>
</tr>
<tr>
<td align="left" valign="top"> </td>
</tr>
</table>
</form>
</body>
</html>
//sampleposteddata.php
<?php
require("../../../getconnect.php");
$filename="FILENAME";
$value=$_POST['FCKeditor1'];
$data=htmlspecialchars($value);
$qryinsertcoupon = "INSERT INTO cms(filename,content)values('".$filename."', '".$data."')";
$insertcoupon = mysql_query($qryinsertcoupon,$concsn);
if($insertcoupon == false) {
print "Unable to connect to database";
print "<script>";
print "window.location.href(\"../../../index.php\")";
print "</script>";
} else {
$a=mysql_insert_id();
$filename.=$a;
$qryupdate="update cms set filename='".$filename."' where fileid=".$a;
$qupdate=mysql_query($qryupdate);
header("Location: ../../../index.php?module=insert");
exit();
}
?>
//addnewpage.php
<?php
session_start();
require("getconnect.php");
if($_GET['action'] == 'test')
{
$a= $_POST['order'];
$b='';
for($i=0;$i<=(sizeof($a)-1);$i++)
{
if($i==(sizeof($a)-1))
{
$b.=$a[$i];
}
else
{ $b.=$a[$i].",";
}
}
$c=explode(",",$b);
$d=sizeof($c);
for($i=0;$i<=$d;$i++)
{
$selqry="select fileid,content from cms where filename='".$c[$i]."'";
$res=mysql_query($selqry,$concsn);
$row=mysql_fetch_row($res);
$fileid=$row[0];
$filecontent=$row[1];
if($i==$d-1)
{
$fileidarr.=$fileid;
$filecontentarr.=$filecontent;
}
else
{
$fileidarr.=$fileid.",";
}
}
$c1=explode(",",$fileidarr);
$selqry="delete from tempcms";
$example=mysql_query($selqry);
for($i=0;$i<=$d-1;$i++)
{
$selqry="insert into tempcms(tempfileid,tempfilename,tempcontent)values(".$i.",'".$c[$i]."','".$filecontent."')";
$res=mysql_query($selqry,$concsn);
}
}
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>CMS - Add New Page</title>
<script language="JavaScript" src="sort.js"></script>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0"><tr>
<td><font color="#FF0000">
<?php if(isset($_GET['module']) && $_GET['module']=='insert'){echo "New Record Added Succesfully";}?>
<?php if(!empty($_SESSION['message'])) echo $_SESSION['message']; $_SESSION['message'] = ''; ?></font>
</td>
</tr></table>
<form method="post" action="insert.php">
<input type="text" name="addpage" value="" />
<input type="submit" name="addpagebutton" value="Add New Page" /></form>
<form name="form1" method="post" action="addnewpage.php?action=test" onSubmit="selectall('order');">
<table border="0" cellpadding="0" cellspacing="0"><tr>
<td>
<select name="order[]" size="16" multiple="multiple" id="order" ondblclick="selectnone(this);">
<?php
$qry="select tempfilename from tempcms order by tempfileid ";
$res=mysql_query($qry,$concsn);
while($row=mysql_fetch_array($res,MYSQL_BOTH))
{
$filename=$row['tempfilename'];
$id=$row['tempfileid'];
$content=$row['tempcontent'];
?>
<option value="<?php echo $filename; ?>"><?php echo $filename;?></option><?php } ?>
</select>
<input type="submit" name="submit" value="Store this structure" />
<input type="button" value="Up" onClick="up('order');" title="Up" style="padding: 0; margin: 0; height: 22px;" /></td>
</tr>
<tr>
<td align="right"> <input type="button" value="Down" onClick="down('order');" title="Down" style="padding: 0; margin: 0; height: 22px;" /></td>
</tr>
<tr>
<td>
<input type="button" name="Backtoindex" value="Back To Index" onclick="javascript:window.location.href('index.php');" />
</td>
</tr>
</table>
</form>
</body>
</html>
//insert.php
<?php
require('getconnect.php');
$addpage=$_POST['addpage'];
$qry="insert into cms(filename) values('".$addpage."')";
$insertcoupon=mysql_query($qry);
$qry="SELECT max(tempfileid) FROM tempcms";
$id = null;
$res=mysql_query($qry);
if ($row = mysql_fetch_row($res)) {
$id = $row[0];
} else {
print (mysql_error());
}
$id += 1;
$tempqry="insert into tempcms(tempfileid,tempfilename) values('".$id."','".$addpage."')";
$insertcoupontemp=mysql_query($tempqry);
if($insertcoupon == false) {
print "Unable to connect to database";
print "<script>";
print "window.location.href(\"addnewpage.php\")";
print "</script>";
} else {
$a=mysql_insert_id();
header("Location:addnewpage.php?module=insert");
exit();
}
?>