Manju Manju - 2 months ago 22
MySQL Question

Insert ckeditor html code into the database

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

Answer

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...

Comments