Solved

Insert comment problem

Posted on 2007-04-02
3
176 Views
Last Modified: 2013-12-13
Experts.

I'm having some problems with inserting comment using form with word that contains a   '   , example when trying to insert word like simon's, it gives error.

$Query = "INSERT into classifieds (comment) VALUES( '$comment')";
$result=mysql_query($Query);

I tried to use the solution $comment = str_replace("'", "", "$comment"); it works but simon's will becomes simons. Is there a way to insert word with ' without getting an error and can be display on page?
0
Comment
Question by:keiluko
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 18839498
a minor change, and it will work as requested:
$comment = str_replace("'", "''", "$comment");
$Query = "INSERT into classifieds (comment) VALUES( '$comment')";
$result=mysql_query($Query);

0
 
LVL 24

Expert Comment

by:glcummins
ID: 18839514
Is there a reason you chose not to use addslashes()?

$Query = "INSERT into classifieds (comment) VALUES( '" , addslashes($comment) . "')";

This will preserve your data as-is, and still allow it to be inserted without error.
0
 

Author Comment

by:keiluko
ID: 18839546
glcummins: not sure about addslashes, been using the insert command without addslashes. but thanks I will use it in future project.

Thanks all.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question