Mouse51180 Posted November 22, 2014 Share Posted November 22, 2014 I am just starting my first php mysql html page project and having a small issue.So I have a phpMyAdmin server running a database called "Dive_Log_DB". There is a table in this database called "DL_Logbook" I have the following code to test connection to the phpMyAdmin server, test the connection to the Dive_Log_DB database and then create a two column table to just test outputting data to (once I get this working I will work on adding the rest of the data). If I adjust the password to be wrong, I get my error message. If I adjust the database name to be misspelled I get my error message. By correct the information I get my success output statement..so I believe I am connecting to everything correctly. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Web DIve Log Test</title> </head> <?php //Connect to phpMyAdmin: $SQLConnect = mysql_connect('localhost', 'MYUSERNAME', 'MYPASSWORD'); If(!$SQLConnect){ die(' ERROR: COULD NOT CONNECT TO SQL SERVER! ' .mysql_error()); } echo 'SQL SERVER CONNECTION SUCCESSFUL!' ."<br>"."<br>"; //Connect to Dive Log Database: $DBConnect = mysql_select_db('Dive_Log_DB', $SQLConnect); if(!$DBConnect){ die(' ERROR: COULD NOT CONNECT TO DATABASE! ' . mysql_error()); } echo 'DATABASE CONNECTION SUCCESSFUL!'."<br>"."<br>"; //Select which table to pull data from: $records = mysql_query('SELECT * FROM DL_Logbook'); //Pull data for table: While($row = mysql_fetch_assoc($records)){ echo "<tr>"; echo "<td>".$row['number']."</td>"; echo "<td>".$row['depth']."</td>"; echo "</tr>"; }//end while ?> <body> <table width = "100" border="1" cellpadding="1" cellspacing="1" <tr> <th>#</th> <th>Depth</th> <tr> </table> </body> </html> The above code outputs the following page: It is as if for some reason everything is connected, but no data is being grabbed.Does anyone have an idea why I am not getting any data in my table? Thank you for any advise in advance. Quote Link to comment Share on other sites More sharing options...
requinix Posted November 22, 2014 Share Posted November 22, 2014 Are you using the same username and password in phpMyAdmin that you are in your code? Find your php.ini and change two settings inside: error_reporting = -1 display_errors = onThen restart Apache, try your script again, and see if you get any error messages. Quote Link to comment Share on other sites More sharing options...
Barand Posted November 22, 2014 Share Posted November 22, 2014 (edited) Off-topic but a couple of points about your data. Country_name,city_name and place_name should only appear in their respective tables and not in your log table. That should only contain the place_id. Your place table should contain the city_id. Your city table should contain the country id, so if you know the place then you know the city id; if you then know the city_id you then know the country id and you can join the tables to get the names. Is number always a duplicate value of the id value? country | | +----< city | | +-------< place diver | | | | +--------< log >-------+ Edited November 22, 2014 by Barand Quote Link to comment Share on other sites More sharing options...
Solution QuickOldCar Posted November 22, 2014 Solution Share Posted November 22, 2014 It could be case sensitive on your column names While($row = mysql_fetch_assoc($records)){ echo "<tr>"; echo "<td>".$row['Number']."</td>"; echo "<td>".$row['Depth']."</td>"; echo "</tr>"; }//end while 2 Quote Link to comment Share on other sites More sharing options...
Mouse51180 Posted November 23, 2014 Author Share Posted November 23, 2014 Off-topic but a couple of points about your data. Country_name,city_name and place_name should only appear in their respective tables and not in your log table. That should only contain the place_id. Your place table should contain the city_id. Your city table should contain the country id, so if you know the place then you know the city id; if you then know the city_id you then know the country id and you can join the tables to get the names. Is number always a duplicate value of the id value? country | | +----< city | | +-------< place diver | | | | +--------< log >-------+ Thank you for the advice, but the SQL database is actually an export from a program called "Dive Log 5.0"...so I have not control over the structure of the database environment. It could be case sensitive on your column names While($row = mysql_fetch_assoc($records)){ echo "<tr>"; echo "<td>".$row['Number']."</td>"; echo "<td>".$row['Depth']."</td>"; echo "</tr>"; }//end while This was the problem...it was case sensitive. Thank you all for the help. I am sure I will be back here again. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.