Page 1 of 1

database connectivity error

Posted: Sat Sep 26, 2009 4:19 am
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 ???

Re: database connectivity error

Posted: Sat Sep 26, 2009 6:09 am
by jackpf
Your username or password is probably incorrect.

Re: database connectivity error

Posted: Sat Sep 26, 2009 6:12 am
by myaion
yes you've got to check either your username or password that defintely where the bug is

Re: database connectivity error

Posted: Sat Sep 26, 2009 6:59 am
by lipun4u
but it's allowing to access when I tried in mysql console...

Re: database connectivity error

Posted: Sat Sep 26, 2009 9:03 am
by jackpf
Is this on your localhost or your server?

Re: database connectivity error

Posted: Sat Sep 26, 2009 12:53 pm
by lipun4u
this is my localhost.

Re: database connectivity error

Posted: Sat Sep 26, 2009 1:25 pm
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.

Re: database connectivity error

Posted: Sat Sep 26, 2009 1:57 pm
by lipun4u
I have accessed the table from the mysql prompt by using the same user name and password

Re: database connectivity error

Posted: Sat Sep 26, 2009 2:04 pm
by lipun4u
thanx friends for helping me.

it's working now !!

Re: database connectivity error

Posted: Sat Sep 26, 2009 3:16 pm
by jackpf
What did you change?

Re: database connectivity error

Posted: Sat Sep 26, 2009 3:48 pm
by lipun4u
my password was 'iitiit' not iitit...I removed the doubble quotes

Re: database connectivity error

Posted: Sat Sep 26, 2009 5:16 pm
by jackpf
Oh right lol. Nice one.