database connectivity error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lipun4u
Forum Commoner
Posts: 82
Joined: Wed Jul 01, 2009 3:35 am
Location: Mumbai
Contact:

database connectivity error

Post by lipun4u »

I have made a table with following data

Code: Select all

 
mysql> select * from items;
+--------+---------------------+-----------+
| itemid | itemname            | itemprice |
+--------+---------------------+-----------+
|      1 | Paperweight         |      3.99 |
|      2 | Key ring            |      2.99 |
|      3 | Commemorative plate |     14.99 |
|      4 | Pencils (set of 4)  |      1.99 |
|      5 | Coasters (set of 3) |      4.99 |
+--------+---------------------+-----------+
5 rows in set (0.02 sec)

I want to fetch data from this table using this php code..

Code: Select all

 
<?php
        $con = mysql_connect('localhost', 'system', 'iitiit') or die ('unable to connect !!');
        mysql_select_db('db2') or die ('unable to select database !!!');
        $query = 'select * from items';
        $result = mysql_query($query) or die ('Error in query...' . mysql_error());
        if(mysql_num_rows($result) > 0) {
            echo '<table width=100% cellpadding=10 cellspacing=0 border=1>';
            echo '<tr><td><b>ID</b></td><td><b>Name</b></td><td><b>Price</b></td></tr>';
            while($row = mysql_fetch_row($result)) {
                echo '<tr>';
                echo '<td>' . $row[0] . '</td>';
                echo '<td>' . $row[1] . '</td>';
                echo '<td>' . $row[2] . '</td>';
                echo '</tr>';
            }
            echo '</table>';
        }
        else {
            echo 'no rows found';
        }
        
        mysql_free_result($result);
        
        mysql_close($con);
    ?>
But it gives the following warning.
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'system'@'localhost' (using password: YES) in F:\Program Files\Apache Software Foundation\Apache2.2\htdocs\dbs1.php on line 10
unable to connect !!

Can somebody tell me how to fix this ???
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: database connectivity error

Post by jackpf »

Your username or password is probably incorrect.
myaion
Forum Newbie
Posts: 2
Joined: Thu Mar 05, 2009 11:43 pm

Re: database connectivity error

Post by myaion »

yes you've got to check either your username or password that defintely where the bug is
lipun4u
Forum Commoner
Posts: 82
Joined: Wed Jul 01, 2009 3:35 am
Location: Mumbai
Contact:

Re: database connectivity error

Post by lipun4u »

but it's allowing to access when I tried in mysql console...
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: database connectivity error

Post by jackpf »

Is this on your localhost or your server?
lipun4u
Forum Commoner
Posts: 82
Joined: Wed Jul 01, 2009 3:35 am
Location: Mumbai
Contact:

Re: database connectivity error

Post by lipun4u »

this is my localhost.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: database connectivity error

Post by jackpf »

Hmm.

Well, I obviously can't tell you what your username and password are.

Have you got phpMyAdmin? If so, try adding a new user for the database.
lipun4u
Forum Commoner
Posts: 82
Joined: Wed Jul 01, 2009 3:35 am
Location: Mumbai
Contact:

Re: database connectivity error

Post by lipun4u »

I have accessed the table from the mysql prompt by using the same user name and password
lipun4u
Forum Commoner
Posts: 82
Joined: Wed Jul 01, 2009 3:35 am
Location: Mumbai
Contact:

Re: database connectivity error

Post by lipun4u »

thanx friends for helping me.

it's working now !!
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: database connectivity error

Post by jackpf »

What did you change?
lipun4u
Forum Commoner
Posts: 82
Joined: Wed Jul 01, 2009 3:35 am
Location: Mumbai
Contact:

Re: database connectivity error

Post by lipun4u »

my password was 'iitiit' not iitit...I removed the doubble quotes
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: database connectivity error

Post by jackpf »

Oh right lol. Nice one.
Post Reply