我遇到了一个问题,我认为我在MySQL中的insert语句弄乱了输入数据库的字符串。
我有一个insert语句,如这在PHP代码中:
$ sql ='insert into my_table(numeric_id,string_value) values('。$ some_number。',''。$ some_text。')';此后,我得到 $ some_text 从数据库中,它混淆了像 don \'t 这样的字符串,而不是像 \r\\ \\ n 到输出。
任何想法为什么会发生这种情况,我应该改变什么?
解决方案你的某些代码正在执行两次转义。 你只需要找到第二次执行代码即可摆脱它。 / p>
首先你必须打印出你的变量才能看到它的实际内容。 很难理解被盲目的事物,并且基于假设
只需打印出 $ some_text 变量,然后再转义并查看。如果它已经被转义了,那么在代码中的某个地方进行额外的转义。
I am running into a problem where I think my insert statement in MySQL is messing up the strings that get entered into the database.
I have an insert statement like this in PHP code:
$sql = 'insert into my_table ( numeric_id , string_value ) values ( '.$some_number.' , "'.$some_text.'" )';And when later I get the $some_text from the database, it messes up strings like don\'t instead of don't and ads things like \r\n to the output.
Any idea why this is happening and what I should change?
解决方案Some of your code is doing escaping twice. You just have to find the code that does it second time and get rid of it.
first of all you have to print out your variables to see it's actual contents. It's hard as hell to sort out things being blinded and based on assumptions.
Just print out $some_text variable before escaping it and see. if it's already escaped - then additional escaping been done somewhere earlier in the code.
更多推荐
将字符串插入到MySQL中
发布评论