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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.