Solved

Insert comment problem

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xampp tool 12 47
WP_Query multiple custom taxonomies 5 43
php function to remove a file 31 39
Seeking info on how to integrate RETS feed based MLS data into a WordPress site 5 39
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

816 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

10 Experts available now in Live!

Get 1:1 Help Now