Stephen68 Posted May 3, 2009 Share Posted May 3, 2009 I can't seem to get this working with WAMP and I'm not sure why. I'll show you the clean function I run and then the error, hope somebody knows what's wrong. The code works great on working server. I do make the connection to the DB before running the clean function as well. function clean($text) { $text=strip_tags(trim(htmlspecialchars(mysql_real_escape_string($text)))); return htmlspecialchars($text); } Error I get it Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) any help would be great, or should I look into using another home test server? Stephen Quote Link to comment https://forums.phpfreaks.com/topic/156651-solved-wamp-and-mysql_real_escape_string/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 3, 2009 Share Posted May 3, 2009 I do make the connection to the DB before running the clean function as well Then your connection code is failing to make a connection or you are closing the connection for some reason and your code has no error checking (check if the mysql_connect() worked or not), error reporting (output a meaningful message when it does not work), or error recovery logic (don't blindly continue execution of the remainder of the code when there is no connection.) What is your code that makes the connection? Quote Link to comment https://forums.phpfreaks.com/topic/156651-solved-wamp-and-mysql_real_escape_string/#findComment-824893 Share on other sites More sharing options...
Stephen68 Posted May 3, 2009 Author Share Posted May 3, 2009 Ok here is my connection code that I use, pretty sure it's not failing though. //Connection strings to the DB define(db_host, "******"); define(db_user, "*****"); define(db_pass, "******"); define(db_link, mysql_connect(db_host,db_user,db_pass)); define(db_name, "univet"); //mysql_select_db(db_name); if (!db_link) { echo "Could not connect to database at this time"; echo mysql_error($db_link); } if (!mysql_select_db(db_name)) { echo "Could not select datbase at this time"; } Thanks for you help in this Quote Link to comment https://forums.phpfreaks.com/topic/156651-solved-wamp-and-mysql_real_escape_string/#findComment-824903 Share on other sites More sharing options...
PFMaBiSmAd Posted May 3, 2009 Share Posted May 3, 2009 The posted code does not prevent execution of the remainder of the code when there is an error connecting to or selecting the database. Add an exit; statement after each of the the last echo statements inside of each of those if() {} conditional blocks. Either the connection code is not be executed at all, your connection is not working and your error messages are not being seen (have you done a "view source" in your browser because if the errors being output by your code are inside of some types of HTML tags they won't be displayed), or your code is closing the connection. What is the full code that is using the connection code and that has the Warning: mysql_real_escape_string() ... error? Quote Link to comment https://forums.phpfreaks.com/topic/156651-solved-wamp-and-mysql_real_escape_string/#findComment-824909 Share on other sites More sharing options...
Stephen68 Posted May 3, 2009 Author Share Posted May 3, 2009 Thanks you have cleared it up and I feel kind of silly. The code was in php tags like this <? ?> I have my server set up not to use shot tags so all I had to do what change it to <?php doh! Thanks for you time and help Stephen Quote Link to comment https://forums.phpfreaks.com/topic/156651-solved-wamp-and-mysql_real_escape_string/#findComment-825074 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.