Error is insert mysql with CKeditor

This is my code:
I have repaced the users, pw en database. The connection is not a problem Buth i get always this error.
I work with the ckeditor…
why it don’t works ???

This is my code:

echo "Make Connection ";

$conn = mysql_connect(‘localhost’, ‘aaaat’,‘bbbb’,‘ccc’) or die(“Database is not connected”);
echo " End Connection";

$title = trim($_POST[“title”]);
$body = $_POST[“myeditor”];
//$body = mysql_real_escape_string($_POST[“myeditor”]);
echo $body;
$date = date(“d M, Y H:i:s”);
echo "Dit is de SQL: ==> ";
$sql = “INSERT INTO ‘WebisteTekst’ (body) VALUES (’$body’)”;

//$sql = “INSERT INTO ‘WebisteTekst’ VALUES(’’,’$title’,’$body’,’$date’)”;
echo $sql;
echo “”;
if (!mysql_query($sql,$conn))
{
die(‘Error in querry.’ . mysql_error());
}
echo “record added”;
mysql_close($conn)

I get the next result

Make Connection

End Connection

Pakher! We are building a simple editor.

Dit is de SQL: ==> INSERT INTO ‘WebisteTekst’ (body) VALUES (’

Pakher! We are building a simple editor.

')
Error in querry.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 ‘‘WebisteTekst’ (body) VALUES (’

Pakher! We are building a simple editor.

’ at line 1

First, mysql is no longer used on any servers. You need to update to mysqli (mysql-improved) or even better, learn PDO which is much more secure.

Next, when you insert data into a database with MySQL or MySQLi, you do it like this:
INSERT INTO table_name (column1, column2, column3,…)
VALUES (value1, value2, value3,…)
In your example, you have quotes around the table name. This is not needed.
Also, if you are using a plug-in text library such as CKeditor, you most likely will need to “ESCAPE” the data pulled out of the request from it. For instance, if you enter a quote or apostrophe, and you insert the value using ‘$body’ in your VALUES list, then, it will mess up what is put into your query. You might need to use ADDSLASHES or MYSQL_REAL_ESCAPE_STRING which really depends on what you are allowing to be entered into the text body area.

Hi,

I have changet it to (mysqli)

$body = (mysqli_real_escape_string($conn, $_POST[“myeditor”])) ;
echo “”;

$date = date(“d M, Y H:i:s”);
echo "Dit is de SQL: ==> ";
$sql = “INSERT INTO WebisteTekst (body) VALUES (’$body’)”;

Is still get the error

Dit is de SQL: ==> INSERT INTO WebisteTekst (body) VALUES (’

Pakher! We are building a simple editor.

\r\n’)
Error in querry.

if (!mysql_query($sql,$conn))

Should be:

if (!mysql_query($conn,$sql))

Otherwise it looks good.

I have change it , Thkx fot the support
Result:

Make Connection

End Connection-------------------------
direct van ingave: -

I Test It Again

\r\n-
Dit is de SQL: ==> INSERT INTO WebisteTekst (body) VALUES (’

I Test It Again

\r\n’)

record addedSuccess: A proper connection to MySQL was made! The my_db database is great. Host information:

Congratulations! It is always very nice to solve a programming puzzle. See you in your next post…

Sponsor our Newsletter | Privacy Policy | Terms of Service