-4

i was wondering how can i include everything written on my textbox to be inserted in mysql database

for example:

textbox = "{\buildrel{\lim}"

but what happens is the \ (backslash) remove 'b' and 'l' and the data inserted to my database will be

{uildrelim} somewhat like this, it might come up removing the { } as well

so is there any techniques or method you can advise? so that everything i put in my textbox will be inserted to my database as it is.

I found this solution:

i just need to use the str_replace() method to replace single \ with double \\

$textbox = str_replace('\\\','\\\\\\\',$textbox);

where {\buildrel{\lim} will be {\\\buildrel{\\\lim}

CodeShark
  • 1,709
  • 2
  • 14
  • 22
  • 2
    If you find an answer please post it as an answer. But `str_replace()` is definitely **not** the answer to your problem as it will not properly escape MySQL strings. – Sébastien Oct 05 '13 at 15:30

1 Answers1

0

No, You dont use str_replace(), you have addslashes() and stripslashes(), those two are the two functions you are looking for.

Changing a string with str_replace functions isnt a smart thing to do. Those functions aren't created with this in mind, the add/striposlashes are. You might forget a character which you needed to str_replace with a slash.

Also, that whole battery of slashes and escaping slashes doesnt make your code very readable :P

Martijn
  • 15,791
  • 4
  • 36
  • 68