Jump to content

[SOLVED] WAMP and mysql_real_escape_string


Recommended Posts

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

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?

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

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.