Solved

Posting " in string

Posted on 2002-04-26
3
206 Views
Last Modified: 2006-11-17
Hi,

How do I insert " into a database? I use mysql.

thanks,
Floris.
0
Comment
Question by:florisb
3 Comments
 
LVL 6

Expert Comment

by:andreif
ID: 6971295
try this to replace " with \"

Don't forget that sometimes PHP requires extra slashes when you compose string:

$sql = "insert .... values (\"here is \\\" char  \")";

in this example \\\" stands for
\\ - slash
\" - quote
so, string will contain only \"
0
 
LVL 2

Expert Comment

by:jpoesen
ID: 6971822
andreif is right.

to make it a bit easier, you can do it like this :

$Title = "Molly the Bear said : \"Wow dude, honey!\""
$SqlQuery = "INSERT INTO Titles VALUES($Title)"

0
 
LVL 5

Accepted Solution

by:
dkjariwala earned 75 total points
ID: 6971996
Basically you need to use addslashes.

Say you have

$check = "hi'hello";

then $check2 = addslashes($check) would give you,
$check2 = "hi\'hello".

JD
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

Suggested Solutions

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 how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

895 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

19 Experts available now in Live!

Get 1:1 Help Now