Trouble getting info from mysql databases

NerdHerd

New Member
Messages
8
Reaction score
0
Points
0
I'm having trouble getting information that is in the mysql database I created and displaying it on my site. This site was one I did as a project for a web design class I took last semester, and everything worked just fine. But when I copied over all the files to x10 and made the changes in the php (username, password, database, and server for mysql_connect() and mysql_select_db() ) it wouldn't grab the info. The php I'm using to connect is:

<?php
mysql_connect("localhost", "nhsadmin_admin", "*********") or die('There was a problem connecting to the mysql server. Error returned: '. mysql_error());
mysql_select_db("NHS") or die('Could not select database');
?>

I'm not getting any error messages about not being able to connect to the database, and when you go to the acual page (https://huntingdonnhs.x10hosting.com:2078/public_html/membersMeetings.html) on the site it looks as if there's something wrong with the php and html that creates the table the info is put into. I haven't made any changes to that part of the page, so it should be ok since it worked perfectly fine on my college's web server and database, which has left me puzzled. I'm kinda new to this site, so I tried attaching the .html file for the page to this but am not sure if it worked or not. Unfortunately, I don't have a lot of time to work on it now since I'm in a new semester, so any help would be greatly appreciated. Thanks.
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
well, first of all, the link to the site is broken. you are linking us to your cpanel and a https:// link. which most browsers find dangerous. anyways. It looks like it isnt retriving the data from the database. Is the table names and data bases exactly the same as they were on your colleges mysql database? If they arnt, you will have to change the table name in your code.

His source code:
HTML:
<!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=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="NHS_CSS.css" />
<style type="text/css">
th
	{color:#FFFFFF;
	background-color:#000000}
td
	{border-top-color:#000000;
	border-top-width:1px;
	border-top-style:dashed}
.white
	{background-color:#FFFFFF}
.darkgray
	{background-color:#999999}
.lightgray 
{background-color: #CCCCCC;}
table
	{border:2px solid #000000}
#mainfloat
	{width:250px;
	position:relative;
	float:left}
#mainfloat2{
	float:right
}
</style>
<title>Untitled Document</title>
</head>

<body>
<?php
mysql_connect("localhost", "nhsadmin_admin", "*********") or die('There was a problem connecting to the mysql server. Error returned: '. mysql_error());
mysql_select_db("NHS") or die('Could not select database');
?>


<div id="container">
  <div id="header"><h1>HAHS National Honor Society</h1>
  </div>

  
  <div id="main">
    <div id="topNavigation">
	    <a href="index.html">NHS Home</a> |
	    <a href="membersHome.html">Members Home</a> |
	    <a href="membersEvents.html">Events</a> |
		Meetings |
	    <a href="membersCommittees.html">Committees</a> |
		<a href="membersByLaws.html">By-Laws</a>
	</div>
	
	<div id="content">
	  <h2>Meetings</h2>
	  <?php
	  $rat = mysql_query("select * from meetings order by year asc");
	  $x=0;
	  while($row = mysql_fetch_array($rat)){
	  	$output[$x] = $row; 
  		$x++;
  	  }
	  ?>
	  <table>
	  	<tr>
			<th>Name</th>
			<th>Date</th>
			<th>Time</th>
		</tr>
		<?php
		
		foreach($output as $value3){
			if(($counter % 2) == 0){
				echo"<tr class=\"white\">
					<td>$value3[Name]</td>
					<td>$value3[Date]</td>
					<td>$value3[Time]</td>
				</tr>";
	    	}
	    	else{
	        	echo"<tr class=\"lightgray\">
					<td>$value3[Name]</td>
					<td>$value3[Date]</td>
					<td>$value3[Time]</td>
				</tr>";
	    	}
	    	$counter++;
		}
		?>
	  </table>
	</div>

  </div>
  
  <div id="footer">Site Design by Shane Pile
  </div>
</div>
</body>
</html>
 

NerdHerd

New Member
Messages
8
Reaction score
0
Points
0
The database name is: nhsadmin_NHS
The username for it is: nhsadmin_admin
I have the correct password.

Those three I had to change for x10. Because there were other people using the same database, I had to have my college username as part of table names, so I only removed my username from the table names, otherwise they're the same. And if that link to the page wasn't working, then this one hopefully should: http://huntingdonnhs.x10hosting.com/membersMeetings.html
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
are you sure that ALL the tables, and rows in the tables are correct?
 

NerdHerd

New Member
Messages
8
Reaction score
0
Points
0
All table names and row names in the tables are correct. When I view the file it almost looks like the php is cutting out for some reason before the ending php tag down where I'm creating the table.
 

deadimp

New Member
Messages
249
Reaction score
0
Points
0
I think you need to learn a little more about PHP before you publish some of your content.
You're using a *.html file extension when you should be using *.php.

With it as it is now, the server doesn't have PHP execute the file, so all of your code is exposed. I would suggest fixing it (and changing your password) as quickly as possible.

I'd suggest you test your site on a local server. Using XAMPP is pretty simple to do.
 
Last edited:

NerdHerd

New Member
Messages
8
Reaction score
0
Points
0
Problem has been taken care of. My instructor (wasn't an actual Professor) apparently never felt like mentioning that our college has things set up so you can get away with using php in .html files. I'm just lucky that my roommate is a nicer person and told me about it. Thanks for the help.
 
Top