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);
?>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 ???