D&C Lug - Home Page
Devon & Cornwall Linux Users' Group

[ Date Index ][ Thread Index ]
[ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] PHP Scripts Continued



Richard Brown wrote:
Thanks Neil

As soon as I renamed it php instead of php3 it worked!

And so I built my first script to access a database called "allusers"
with a table called "names" and having the fields "firstname",
"lastname", "streetaddr", "distaddr", "city", "county", "postcode",
"country".

Here is the script:-
<html>
<body>

<?php
$db=mysql_connect("localhost","root");
mysql_select_db("allusers",$db);
$result=mysql_query("SELECT*FROM names",$db);
printf("firstname:%<br>\n",mysql_results($result,0,"firstname"));
printf("lastname:%<br>\n",mysql_results($result,0,"lastname"));
printf("streetaddr:%<br>\n",mysql_results($result,0,"streetaddr"));
printf("distaddr:%<br>\n",mysql_results($result,0,"distaddr"));
printf("city:%<br>\n",mysql_results($result,0,"city"));
printf("county:%<br>\n",mysql_results($result,0,"county"));
printf("postcode:%<br>\n",mysql_results($result,0,"postcode"));
printf("country:%<br>\n",mysql_results($result,0,"country"));
?>

</body>
</html>

It doesn't do what I want it to do. i.e. Display all the records! Here
is the output from Mozilla.

Warning: Access denied for user: 'root@xxxxxxxxx' (Using password: NO)
in /var/www/html/test.php on line 5

Question> Does your MySQL database have a password for the user 'root' ? you can check this by running 'mysql -u root' at a command line.


Everything will make more sense once you have fixed this part, it is generally a good idea to add a different user who has permissions over the database you are trying to read from a username such as that the same as the database is usually quite easy to remember..

HTH

Neil


-- The Mailing List for the Devon & Cornwall LUG Mail majordomo@xxxxxxxxxxxx with "unsubscribe list" in the message body to unsubscribe.


Lynx friendly