How to insert quotation marks to a mysql db?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

How to insert quotation marks to a mysql db?

Post by JKM »

Hi there!

I was wondering how I could insert quotation marks (") to a mysql db. I want to insert some html codes (<a href="lol.html" target"_blank">lol</a>).

Thanks for any help
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: How to insert quotation marks to a mysql db?

Post by califdon »

Use the escape (backslash) character.
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

Re: How to insert quotation marks to a mysql db?

Post by JKM »

Code: Select all

$about = str_replace('"', '\"', nl2br($_POST['about']));
mysql_query("INSERT INTO xxx (about) VALUES ('$about')");
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 'bla bla bla bla blab al' at line 1
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: How to insert quotation marks to a mysql db?

Post by VladSun »

Use mysl_real_escape_string()
There are 10 types of people in this world, those who understand binary and those who don't
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

Re: How to insert quotation marks to a mysql db?

Post by JKM »

Sorry guys, I was too fast with the c/p so there was two quotes in stead of one. :-p
Post Reply