mysql_real_escape_string() just makes an empty string?

徘徊边缘 提交于 2019-11-30 18:57:03

Are you 1000% sure that $_POST["likeMsg"] actually contains something?

As for mysql_real_escape_string() returning an empty value, the manual says there is only one situation where that can happen:

Note: A MySQL connection is required before using mysql_real_escape_string() otherwise an error of level E_WARNING is generated, and FALSE is returned. If link_identifier isn't defined, the last MySQL connection is used.

this doesn't seem to be the case here though, as you do have a connection open. Strange.

As the other answers don't make clear what exactly to do, here's my:

When you do

$db_connection = new mysqli($SERVER, $USERNAME, $PASSWORD, $DATABASE);

you need to escape like this:

$newEscapedString = $db_connection->real_escape_string($unescapedString);

NOTE: Because people are downvoting this (WTF!?), here's the official page of the official php manual that says EXACTLY what i have posted: real_escape_string @ PHP Manual.

For people who might be finding this again now, I just ran into this problem as I'm migrating from PHP5 to PHP7. I'm changing from

string mysql_real_escape_string(string $unescaped, [resource $link = NULL])

to:

string mysqli_real_escape_string(mysqli $link, string $escapestr)

So, in other words, the database $link is no longer optional and moves to the first argument position. If left out, it returns an empty string, without an error, apparently.

Do a var_dump of $_POST['likeMsg'], and a var_dump of $likeMsg. That gives you information on what goes wrong.

mysql_real_escape_string() will return blank response if you have not made connection to database ...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!