P
P
profseo20122016-01-14 18:36:18
PHP
profseo2012, 2016-01-14 18:36:18

Json_decode. Error adding to database?

Problem adding to database.
There is a form that works on Ajax Json PHP. I use json_decode, an error occurs when adding to the database.
Initially it didn't work with adding text in double quotes, I solved the problem like this:
$value = str_replace("\"", "", $value);
$value = str_replace('\\', '/', $value);
$ value = preg_replace('#(\.|\?|!|\(|\)){3,}#', '\1', $value);
Now everything works fine, but when entering the "&" sign into the field an error occurs when adding to the database
Please help!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nazar Mokrinsky, 2016-01-14
@nazarpc

Initially did not work with adding text in double quotes

Don't shoot yourself in the head, use mysqli_real_escape_string() or PDO, that's what they are for.
Because such regular expressions are a highway for SQL injections.

W
winbackgo, 2016-01-14
@winbackgo

See mysqli_real_escape_string

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question