views:

177

answers:

2

Hey, I have this strange problem.

I have this script:

echo $comment_content = $_POST['comment_content'];
echo $comment_content = mysql_real_escape_string($comment_content);

When I run it on my website server, it outputs the value only 1 time (not the second one), but when I run it anywhere else, it outputs right (2 times). However, I use function mysql_real_escape_string many times (on the same site) and it never happened before.

This is the whole code, nothing more.

Anyone ever had the same problem? If yes, how did you fix it?

Mike

edit: the <?php ?> tags also there ofc.

A: 

Check your queries and connections. If I recall correctly, if there is a problem with the preceding query or connection it causes mysql_real_escape_string to fail also. I hit that snag when I first started with PHP + MySQL.

Annath
So what exactly should I look for? :/
Mike
True, it needs valid connection data to work. However, normally you'd see at least one big fat warning if PHP was unable to connect to the server.
Thorarin
+4  A: 

mysql_real_escape_string needs an existing MySQL connection. No connection, no escaping.

Philippe Gerber
Thanks! It was it. But on the other hand, how come that on the other server I was testing it on, it worked even without it? :-)
Mike