Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Use of ' in MYSQL causing syntax error
Old 04-25-2006, 01:58 PM Use of ' in MYSQL causing syntax error
Super Talker

Posts: 129
Trades: 0
Hi all, first post hope someone can be of help. I have a website that uses an MYSQL guest book. I've noticed that if someone uses the ' around text it causes a syntax error. The " does not. This is occurring in the comments field which is set to TEXT. I've tried changing to VARCHAR to no avail. I've done some SQL and I seem to remember the ' being used to designate literals etc. How can I get round this problem?

Cheers, Lol
Lol999 is offline
Reply With Quote
View Public Profile Visit Lol999's homepage!
 
 
Register now for full access!
Old 04-25-2006, 02:52 PM Re: Use of ' in MYSQL causing syntax error
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
the ' is a delimiter in SQL

you need to "escape" them in whatever server-side language you use

PHP you can use the add_slashes function.

ASP would be replace(SQL_String,"'","''") (that's two single quotes BTW)
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-25-2006, 04:20 PM Re: Use of ' in MYSQL causing syntax error
Super Talker

Posts: 129
Trades: 0
Thanks Chris. I have to confess my guestbook is a downloaded PHP script that i incorporated into my site. having never used PHP what code would I need to use and where would I put it?

Cheers, Lol
Lol999 is offline
Reply With Quote
View Public Profile Visit Lol999's homepage!
 
Old 04-25-2006, 04:46 PM Re: Use of ' in MYSQL causing syntax error
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
Run a search through the code for any occurrences of 'INSERT' (or 'insert'). The queries will contain php variables, and you need to find the one that holds the data for the comments field, and escape the value before it ends up in the query, so on a line before the query add something like
PHP Code:
$comments addslashes($comments); 
($comments being the variable holding the comments data, the name may differ in your code).
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 04-25-2006, 04:49 PM Re: Use of ' in MYSQL causing syntax error
Super Talker

Posts: 129
Trades: 0
Perfect Oberon! Your'e an angel ;-)

Thanks, Lol
Lol999 is offline
Reply With Quote
View Public Profile Visit Lol999's homepage!
 
Reply     « Reply to Use of ' in MYSQL causing syntax error
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 6.01508 seconds with 12 queries