Problem with single quotes in 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
chriso
Forum Commoner
Posts: 31
Joined: Fri Aug 01, 2003 11:52 am

Problem with single quotes in mysql db

Post by chriso »

I have a table called crs_desc with a data type of longtext. When I bring up this field in a form to be edited the text is surrounded by single quotes. For example:

'This is a bogus course for messing with'

Now, if I edit the text and delete the single quotes the text is updated with no problems. However, if I don't delete the single quotes, I get the following error message:

Error updating course information: 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 'This is a bogus course for messing with'' WHERE ID = '36'' at

Is there a way I can remove the single quotes before displaying the text for editing or is there another data type I should be using? I don't have to use longtext so I'm open for other datatypes. However, I don't want to limit the field to 255 char. because the course description may be longer than that.

BTW, when I display the field in an html document for just viewing, the single quotes are not displayed. It's only when its displayed in a form field that they appear.

Thanks for the help!
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

I think this may help you.
http://www.mysql.com/doc/en/BLOB.html

What is the rest of the code?
chriso
Forum Commoner
Posts: 31
Joined: Fri Aug 01, 2003 11:52 am

Post by chriso »

Maaaaannnnn!! 8O I can't believe I did that :oops: In my code I put the single quotes around the variable. Don't know what I was thinking. Took them out and all is well. :D Silly me.

Regards,
Chris.
Post Reply