Jump to content

[Answered] Mysql Error Message In Php Script.


Recommended Posts

Posted

I'm getting the message below on a PHP script I'm using. It happens in a part where I'm using an AJAX chainselect drop-down menu. I can't figure out why this is showing up and how to fix this.

 

What is really frustrating is that is doesn't happen all the time. Some selections work and some don't.

 

 

Warning: mysql_query() [function.mysql-query]: Access denied for user 'leamsp'@'localhost' (using password: NO) in /home1/leamsp/public_html/prospect/func.php on line 28

 

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home1/leamsp/public_html/prospect/func.php on line 28

Access denied for user 'leamsp'@'localhost' (using password: NO)

 

 

Here is a test page ...

 

http://leamspworldwide.heliohost.org/prospect/

Posted

Just to make sure, did you fix it already? Your link works and viewing func.php doesn't produce any errors.

  • Like 1
Posted

I figured it out.

 

It turns out that the script I was using it on (not the test script that I listed), connects to the MySQL database and displays data on the web page from that database. The AJAX chainselect menu is also on that page. When you select something, the javascript (AJAX) does a get to another PHP script to display the 2nd tier of the menu. It's at that point where it failed. Both my page data AND the AJAX scripts are using the same database (but different tables).

 

So, to make a long story short ....

I'm essentially connecting twice to the same database.

 

My fix ....

 

On the main page, I am now doing this:

 

mysql_connect("localhost", "lechtes", "mypassword") or die(mysql_error());

mysql_select_db("lechtes_profile") or die(mysql_error());

 

 

On the AJAX script (func.php) that is processing the chainselect, I am now doing this:

 

mysql_connect("localhost", "lechtes", "mypassword",TRUE) or die(mysql_error());

mysql_select_db("lechtes_profile") or die(mysql_error());

 

 

The 2nd connection is a "new link" to the same database (using the new link parameter).

 

That eliminated the MySQL connection errors.

 

Thanks everyone for this forum. I've learned a lot by looking at other posts as well.

Discussions on this forum that I don't find on other forums ... nice!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...