2

How do I insert a value in MySQL that consist of single or double quotes. i.e

Ali said, "This is Ashok's Pen." 

The single quote will create problems. There might be other escape characters.

I am using php to enter data into the database?

How do you insert the data properly?

Abrar Ahmed
  • 79
  • 1
  • 3
  • 11
  • read [mysql_real_escape_string](http://php.net/manual/en/function.mysql-real-escape-string.php) – Saty Nov 16 '15 at 12:20
  • 1
    You need to escape it somehow. Use mysqli_real_escape_string or even better PDO and prepared statements. – Kostas Mitsarakis Nov 16 '15 at 12:20
  • *"I am using php to enter data into the database?"* - I don't know, are you?? show your code for the SQL. – Funk Forty Niner Nov 16 '15 at 12:22
  • Hello! I get the error Slug : mon-oncle-1958 Mon OncleError: UPDATE yts SET plot ='Monsieur Hulot visits the technology-driven world of his sister, brother-in-law, and nephew, but he can't quite fit into the surroundings.' WHERE `imdb` ='tt0050706' 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 't quite fit into the surroundings.' WHERE `imdb` ='tt0050706'' at line 1 – Abrar Ahmed Nov 16 '15 at 13:38

2 Answers2

2

You need to use \ (Escape) character to insert single quotes and double quotes.

INSERT INTO table_name(`clomn1`) VALUES ('Ali said, "This is Ashok\'s Pen."')
Dharman
  • 26,923
  • 21
  • 73
  • 125
Subin Chalil
  • 3,368
  • 2
  • 22
  • 38
0

Use mysqli_real_escape_string() mysqli_real_escape_string

Sanjay Kumar N S
  • 4,397
  • 3
  • 20
  • 38