-1
$data = "INSERT into detail(id,event) VALUES (1,"quest '15")";

Im having trouble with the single quote '15.i tried to use \'15 but doesnt seem to work.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
karthick prasad
  • 103
  • 2
  • 9

4 Answers4

0

try this:

$data = "INSERT into detail(id,event) VALUES (1,\"quest '15'\")";
OnlyMAJ
  • 819
  • 8
  • 21
0

Try this: $data = "INSERT into detail(id,event) VALUES (1,'quest \'15')";

Sha Beer
  • 27
  • 3
  • 9
0

The problem isn't the single quote; the problem is the use of double quotes within a string literal that is enclosed in double quotes. Your double quoted string literal is actually being ended right before quest.

One alternative is to use single quotes for string literals within SQL text. Within a string literal, you'll need to "escape" the single quote, and one way to do that is by preceding a single quote by another single quote.

For example:

$data = "INSERT into detail(id,event) VALUES (1,'quest ''15')";
                                                ^      ^^  ^

If you do that, the value for the event column will be seen as quest '15

spencer7593
  • 106,611
  • 15
  • 112
  • 140
0

I strongly suggest using prepared statements, but in lieu of that, you can use mysqli_real_escape_string.

$data "INSERT INTO detail (id, event) VALUES (1, '".mysqli_real_escape_string("quest '15")."')";
Daniel
  • 4,481
  • 14
  • 34