Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6339839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:43:26+00:00 2026-05-24T19:43:26+00:00

Warning for my php file.. Warning: mysql_query() [function.mysql-query]: Access denied for user ‘ODBC’@’localhost’ (using

  • 0

Warning for my php file..

Warning: mysql_query() [function.mysql-query]: Access denied for user ‘ODBC’@’localhost’ (using password: NO) in C:\Program Files\xampp\htdocs\shadaab\register.php on line 25

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\Program Files\xampp\htdocs\shadaab\register.php on line 25
Access denied for user ‘ODBC’@’localhost’ (using password: NO)

My Connection File:

$localhost='localhost';
$username='root';
$password='';
$dbname='school';

$con=mysql_connect('$localhost','$username','$password');
mysql_select_db('$dbname',$con);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T19:43:27+00:00Added an answer on May 24, 2026 at 7:43 pm

    Final Update:

    I opened a chat session with Aditii and we did some debugging there.

    As it turns out, the problem was that she had upgraded from a server which had short tags enabled to one that did not. As a result, all of her code that was enclosed in short tags was not being executed, and this included her configuration file.

    The error in the question was due to the mysql_connect() function not being executed because that whole file was not being executed. A mysql_query() call that relied on that connection failed because of this.

    After correcting her short tags to use the full <?php tag, that file executed. As discussed in my original answer to this question, the single quotes around the variables being passed to mysql_connect() did end up causing problems. After advising that those single quotes be removed, the connection succeeded and the problem was resolved.

    The entire debugging session, for any interested parties, can be found here.


    First Update:

    After looking at this a bit closer, there are two pieces that don’t fit my original response (which I’ve kept at the bottom of this answer, since it still has some good info in it).

    First, the error is being triggered by mysql_query() not mysql_connect(). This is probably because there is no error handling surrounding the connection, so the error doesn’t get noticed until later. Try adding some error handling around the connection:

    if (!($con = mysql_connect('$localhost','$username','$password'))) {
      echo mysql_error();
    }
    
    if (!mysql_select_db('$dbname',$con)) {
      echo mysql_error();
    }
    

    In the above, errors will be displayed as soon as the error occurs.

    The second thing I see is that you’re connecting to localhost with the ODBC user. This makes no sense if the error is being triggered by the connection code you’ve shown above. Either you would be logging on with a user called $username if your problem is the single quote issue I explain below, or root if you’re not.

    It looks like PHP is trying to connect with the default credentials for your PHP setup (found in your php.ini file), rather than the credentials you’ve supplied. This leads me to believe that the lines you’re showing us aren’t actually the lines being executed. Are you sure that you’re not trying to connect elsewhere in your code? If you are, I suspect that your error lies in that portion of the code.

    It’s also possible (I would have to check) that when you’re attempting to run mysql_query() against a null connection, maybe PHP is trying to create a connection for you. I wouldn’t count on that though.

    I suggest you try running the updated code I’ve provided above, which uses the mysql_error() function to show errors as they happen. You could even add in some echo statements of your own in those blocks, for some good old fashioned printf debugging.


    Original Answer:

    The problem is that you’re wrapping your variables inside single quotes. If you wrap them in single quotes, PHP doesn’t evaluate the variable to the value. For example, rather than passing root as the second argument, you’re passing $username. In the end, you’re trying to log into a server called $localhost with a user called $username with a password of $password.

    Take a look at the PHP documentation page for Strings. It explains this:

    Note: Unlike the double-quoted and heredoc syntaxes, variables and escape sequences for special characters will not be expanded when they occur in single quoted strings.

    If you want to use variables inside of a string, you need to use double quotes, not single. In this case, however, you don’t even need to wrap these variables in quotes at all, because their values are already strings. You can just pass the variable all by itself. Try this:

    $con=mysql_connect($localhost, $username, $password);
    mysql_select_db($dbname, $con);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I try to include a file using include_once in php which shows warning
I'm getting this problem: PHP Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable
I am using the Database Backup script by David Walsh( http://davidwalsh.name/backup-mysql-database-php ) to backup
I'm having trouble opening MySQL's slow query log with PHP. I'm writing a debugger
I have a situation where I would like to use a php file query.php
Hey i'm trying to make my website delete a file using the unlink(); function.
php -v gives this PHP Warning: PHP Startup: memcache: Unable to initialize module Module
I'm getting this PHP warning in my error_log and want to get it fixed.
I am getting the following errors: PHP Warning: Module 'ldap' already loaded in Unknown
When I run player.php it's giving this error: Warning: Cannot modify header information -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.