I've been trying to figure out what I am not doing correctly when using the mysql_real_escape_string function. I set up a test file that only contains (config.php are my mysql settings): <?php include('config.php'); echo(mysql_real_escape_string("The next line won't work")); $fixed = mysql_real_escape_string("Now it's working!"); echo($fixed); ?> Code (markup): and the resulting output is: Second line doesn't show up... Any time I try to use mysql_real_escape_string within a variable, it breaks the code. Any ideas what's happening? -- JK
Have you made an actual mysql connection? mysql_real_escape_string requires you are connected in order to use it. It's strange that the first one works and the second will not and that's the only thing I can think of at this moment that may cause this.
Yes, the connection is established in the 'config.php' file and I am able to make queries to the database.
So if you do something like <?php include('config.php'); $fixed = "I AM NOT FIXED"; $fixed = mysql_real_escape_string("Now it's working!"); echo $fixed; ?> PHP: You get what values back exactly when you echo fixed? I'm going to assume you get nothing so do var_dump($fixed); and see what it gives you for the type of $fixed. I assume it will be a boolean and be FALSE.
What's your error reporting set to? Add error_reporting(E_ALL); echo(mysql_real_escape_string("The next line won't work")); PHP: to the top of your file (yes, before config.php). Perhaps PHP is not outputting errors. The only reason I have said this, is because the 2nd line should thow an error saying there is no MySQL resource link. If it does, remove it and refresh, and see if any more errors are outputted. If there is no error, PHP.ini is set not to display_errors (try using ini_set()). Jay
Thanks for the help on this issue. I have found the problem, which is of course the stupidest user error. There were invisible non-breaking spaces on both sides of the '=' following the variable. I had to show invisibles in order to see that there was something funny going on. Probably from copying and pasting in the process. Switched to regular spaces and all is right with the world. I knew it was something ridiculously stupid like that. -- peon