1

I try to insert this information in Mysql database

$mytext = "this is a word in french d'origine francaise";

Then the PHP sql code:

$sql = "INSERT INTO tchapter (content) VALUES ('". $mytext ."')";

It will send me an error because i have a ' apostrophe character in the $mytext, in fact it will mix between the apostrophe '". $mytext ."' that exist in the $sql.

My question is what is the proper way to prepare the text to be entered in a database to prevent any type of error with the special character.

Also i should get back the text from the database as it appear before in the html page.

3

1 Answer 1

1

You can escape your string using the following function, prior to inserting in the database

mysql_real_escape_string()

Sign up to request clarification or add additional context in comments.

1 Comment

Please don't recommend deprecated functions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.