How to handle single quote in insert field

Codes here !

Moderators: egami, macek, gesf

Post Reply
fredws
New php-forum User
New php-forum User
Posts: 14
Joined: Wed Jul 16, 2003 4:16 pm

Thu Apr 29, 2004 11:10 am

I am getting an error, and I think that it is due to an apostrophe.

Such as:

INSERT into table1(memo) values ('{$myrow["memo"]}')

which seems to give me fits if what is typed into the memo field is as:

"Dad's phone number is bla bla bla"

The apostrophe seems to mess up the query. How do you go about this?

TIA,
Fred
User avatar
swirlee
Moderator
Moderator
Posts: 2257
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Thu Apr 29, 2004 11:15 am

First of all, never use curly brace syntax. It's ugly. Do this instead:

Code: Select all

$query = 'INSERT into table1(memo) values (\'' . $myrow['memo'] . '\')';
Anyway, the function you're looking for is mysql_escape_string().
Image
Post Reply