Solved

Insert comment problem

Posted on 2007-04-02
3
172 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 142

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now