Jump to content

My first project - Connected but no data - MySQL\PHP


Mouse51180
Go to solution Solved by QuickOldCar,

Recommended Posts

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"

phpMyAdmin_zpsb3e31027.png

 

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:

page_zpsbe3acd37.png

 

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.

Link to comment
Share on other sites

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 by Barand
Link to comment
Share on other sites

 

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.