PDA

View Full Version : سوال: بگارگیری CKeditor در PHP و ذخیره سازی MySQL



amin9750
جمعه 06 مرداد 1391, 17:08 عصر
با سلام
در مورد بکارگیری CKeditor در صفحات وب سئوال دارم و یک نمونه برای

یک صفحه که ادیتور درآن وجود داشته باشد و یک دکمه ذخیره که اطلاعات را در بانک اطلاعاتی ذخیره کند و
یک صفحه که اطلاعات را نمایش دهد

با تشکر

narsisss
شنبه 07 مرداد 1391, 10:05 صبح
PHP :


<?php
// baraye edit e matn

$query = "SELECT * FROM `table` WHERE `name` = 'contentname'";
$result=mysql_query($query) or die ('query failed' . mysql_error());


while ($row=mysql_fetch_array($result))

{
$content =$row['text_content'];

}
if(isset($_POST['submit'])){
$content = $_POST['editor1'];
$query= "UPDATE `table` SET `text_content` = '".$content."' WHERE `name`='contentname';" ;
$result= mysql_query ($query);
$message = "متن با موفقیت ویرایش شد";
}

// baraye ijade matne jadid

if(isset($_POST['submit'])){
$content = $_POST['editor1'];
$query= "INSERT INTO `table` (`text_content`) VALUES ('".$content."');" ;
$result= mysql_query ($query);
}

?>



HTML :



<!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=utf-8" />
<title>CKEDITOR </title>



<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script src="ckeditor/_sample/sample.js" type="text/javascript"></script>
<link href="ckeditor/_sample/sample.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
//<![CDATA[

var editor, html = '';

function createEditor()
{
if ( editor )
return;


// Create a new editor inside the <div id="editor">, setting its value to html
var config = {};
editor = CKEDITOR.appendTo( 'editor', config, html );
}

function removeEditor()
{
if ( !editor )
return;

// Retrieve the editor contents. In an Ajax application, this data would be
// sent to the server or used in any other way.
document.getElementById( 'editorcontents' ).innerHTML = html = editor.getData();
document.getElementById( 'contents' ).style.display = '';

// Destroy the editor.
editor.destroy();
editor = null;
}

//]]>
</script>
</head>

<body>

<form action="#" method="post">
<table style="border:none"><tr >

<td style="direction:rtl; width: auto; float:right ;border-bottom:0; border-left : 0;">
<label >محتوای صفحه</label>
<textarea cols="100" id="editor1" name="editor1" rows="10"><?php echo $content ;?></textarea></td>

</tr>


<script type="text/javascript">
//<![CDATA[
// Replace the <textarea id="editor1"> with an CKEditor instance.
var editor = CKEDITOR.replace( 'editor1' );
//]]>
</script>
<tr>
<td style="border-bottom:0; border-left : 0;"><input type="submit" value="ارسال" name="submit" /></td>
</tr>

</table>

</form>
</body>

</html>

amin9750
سه شنبه 17 مرداد 1391, 21:52 عصر
سلام
ممنونم که راهنمایی کردین
ولی باز هم مشکل من رفع نشد
این تو که توی فایل Sample / PHP وجود داره - 3 راه برای بکارگیری وجود داره
من میخوام یک فایل Edit و View + یک فایل Sql باشه که من متوجه بشم که چطور اطلاعات در SQL ذخیره میشه
ممنون میشم بیشتر راهنمایی کنید
با تشکر