Insert ckeditor html code into the database

淺唱寂寞╮ 提交于 2019-12-11 05:59:26

问题


I am trying to insert the ckeditor text into database,I am able to print the code in html format,while inserting that into the db,iam getting the fallowing error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table' at line 1

INDEX.PHP

<html>
<head>
<script type="text/javascript" src="ckeditor/smaple.js"></script>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
</head>
<body>
<form action="action.php" method="post">
<textarea rows="20" cols="70" class="ckeditor" id="editor1" name="test1"></textarea>
<input type="submit" value="save">
</form>
</body>
</html>

action.php

<?php
echo strip_tags($_POST['test1']);
$content  = $_POST['test1'];
mysql_connect("localhost","root","");
$conn = mysql_select_db("test");
$query = "INSERT INTO table VALUES('','one',mysql_real_escape_string($content)";
echo $query;
if(mysql_query($query))
{
    echo "inserted";
}
else
{
    mysql_error();
}
$display = "select * from table";
$res = mysql_query($display);
if($res)
echo "true";
else
echo mysql_error();
while ($result = mysql_fetch_array($res)) {
    echo $res['content'];
}
?>

please help me


回答1:


Edit the line to read:

$query = "INSERT INTO myTableName VALUES('','one','".mysql_real_escape_string($content)."'";

And make sure you're putting the right value for your table name in place of myTableName...




回答2:


Closing braces for the query is missing.

$query = "INSERT INTO table VALUES('','one',mysql_real_escape_string($content))";



回答3:


It's work for me

index.php

<html>
<head>
<script type="text/javascript" src="ckeditor.js"></script>
</head>
<body>
<form action="action.php" method="post">
<textarea rows="20" cols="70" class="ckeditor" id="editor1" name="test1">       </textarea>
 <input type="submit" value="save">
</form>
</body>
</html>

action.php

<?php
echo strip_tags($_POST['test1']);
$content  = mysql_real_escape_string($_POST['test1']);
mysql_connect("localhost","root","");
$conn = mysql_select_db("test");
$query = "INSERT INTO yourtablename VALUES('','$content')";
echo $query;
if(mysql_query($query))
{
    echo "inserted";
 }
 else
{
mysql_error();
}
 $display = "select * from yourtablename";
 $res = mysql_query($display);
 if($res)
 echo "true";
 else
 echo mysql_error();
   while ($result = mysql_fetch_row($res)) {
   echo $result[1];
  }
  ?>



回答4:


If you are using your table name which is like any keywords from sql then take it in this symbol ` on the top of tab button




回答5:


You can do i without using mysql_real_escape_string($content)

You can directly use $query = "INSERT INTO table VALUES('','one','$content')";



来源:https://stackoverflow.com/questions/22904776/insert-ckeditor-html-code-into-the-database

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!