Received: from rm-rstar.sfu.ca (root@rm-rstar.sfu.ca [142.58.120.21]) by hub.org (8.9.1/8.9.1) with ESMTP id LAA26259 for ; Wed, 2 Dec 1998 11:55:36 -0500 (EST) (envelope-from gburnham@sfu.ca) Received: from apemantus (apemantus.educ.sfu.ca [142.58.6.61]) by rm-rstar.sfu.ca (8.9.1/8.9.1/SFU-5.0H) with SMTP id IAA18453; Wed, 2 Dec 1998 08:55:20 -0800 (PST) Message-ID: <000401be1e14$927876a0$3d063a8e@apemantus.educ.sfu.ca> From: "Gregory W Burnham" To: "S.Ramaswamy" , "PETER PAULY" Cc: Subject: Re: [SQL] Odd characters in inserted data... Date: Wed, 2 Dec 1998 08:55:28 -0800 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 4.72.3155.0 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3155.0 >PETER PAULY wrote: > >> I'm using the "C" interface to write CGI code for a web application. I allow >> the user to type data into a particular field, and am storing that data into a >> field in a postgres database. >> >> The problem is, I have to filter the data that the user entered to remove any >> single quotes and other odd characters so that my SQL command doesn't get >> messed up. I'm building the command with printf and passing the filtered >> data from the user as so: >> >> update tablename set comment = '%s' where ..... >> >> And %s is substituted in the printf with the user data. If the user typed in a >> single quote, it would cause havoc with the sql statement. My question is, is > >you should substitute single quote with two single quotes You can also (keeping with 'C' tradition) substitute \' for the single quote.