?
Solved

Posting " in string

Posted on 2002-04-26
3
Medium Priority
?
238 Views
Last Modified: 2006-11-17
Hi,

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

thanks,
Floris.
0
Comment
Question by:florisb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 300 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

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

800 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