Forum Moderators: coopster
to display the contents of the database every thing i have tried does not work.
1. what i am doing wrong
2. how do you know that you have connected database (database is on a web server not on my PC).
<html>
<body>
<?php
$db = mysql_connect("localhost", "username", "PASSWORD");
mysql_select_db ("body1975_famiytree");
$sql = 'SELECT * FROM `Addresses and Occupations` LIMIT 0, 30 ';
?>
</body>
</html>
HELP PLEASE I AM GOING NUTS!
this thread might help
Basics of extracting data from MySQL using PHP [webmasterworld.com]
I do have a question as well
$sql = 'SELECT * FROM `Addresses and Occupations` LIMIT 0, 30 ';
is Addresses and Occupations the exact tablename in your database?
Table 64 Any character that is allowed in a filename, except ‘/’, ‘\’, or ‘.’In addition to the restrictions noted in the table, no identifier can contain ASCII 0 or a byte with a value of 255. Database, table, and column names should not end with space characters.
[dev.mysql.com...]
But definitely to be avoided in mySQL. It works okay with spaces in Access, but it just makes everything more complicated - all table names must be quoted (Access) or backticked (MySQL), which is a hassle IMO.
I changed the name of the table to ADDRESSES I dont know if this was part of the problem but hey I got somthing to display on my web page, and the link to that other post help alot aswell, I think i will be back with a few more questions.
Here is my NEWBIE starting script below.
<?php
$db = mysql_connect("localhost", "USERNAME", "PASSWORD") or die("Could not connect");
mysql_select_db ("YOURDATABASE_HERE") or die("Could not select DB");
$sql = 'SELECT * FROM `ADDRESSES` WHERE 1 LIMIT 0, 30 ';
$query = mysql_query($sql);
while ($row = mysql_fetch_array($query)) {
echo "<p>",$row['FULLNAME'],": ",$row['YOB']; }
?>