+ Reply to Thread
Results 1 to 7 of 7

Thread: Trouble getting info from mysql databases

  1. #1
    NerdHerd is offline x10Hosting Member NerdHerd is an unknown quantity at this point
    Join Date
    Jan 2008
    Posts
    8

    Question Trouble getting info from mysql databases

    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.

  2. #2
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    Re: Trouble getting info from mysql databases

    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 Code:
    <!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>
    Neil Hanlon | x10Hosting Support Representative
    Neil[at]x10hosting.com
    █ I'm always happy to help. Just ask a question in Free Hosting
    Terms of Service IRC

  3. #3
    NerdHerd is offline x10Hosting Member NerdHerd is an unknown quantity at this point
    Join Date
    Jan 2008
    Posts
    8

    Re: Trouble getting info from mysql databases

    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/...sMeetings.html

  4. #4
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    Re: Trouble getting info from mysql databases

    are you sure that ALL the tables, and rows in the tables are correct?
    Neil Hanlon | x10Hosting Support Representative
    Neil[at]x10hosting.com
    █ I'm always happy to help. Just ask a question in Free Hosting
    Terms of Service IRC

  5. #5
    NerdHerd is offline x10Hosting Member NerdHerd is an unknown quantity at this point
    Join Date
    Jan 2008
    Posts
    8

    Re: Trouble getting info from mysql databases

    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.

  6. #6
    deadimp is offline x10 Sophmore deadimp is an unknown quantity at this point
    Join Date
    Jun 2007
    Posts
    249

    Re: Trouble getting info from mysql databases

    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 by deadimp; 02-04-2008 at 08:54 AM.
    deadimp.org
    > Thacmus [v0.3.0] - Open source CMS, PHP 5, MySQL

    "¡Ya lo sabo!" - Lo Ausente

  7. #7
    NerdHerd is offline x10Hosting Member NerdHerd is an unknown quantity at this point
    Join Date
    Jan 2008
    Posts
    8

    Re: Trouble getting info from mysql databases

    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.

+ Reply to Thread

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 43
    Last Post: 03-24-2011, 07:27 AM
  2. Trouble creating MYSQL database
    By aurona in forum Free Hosting
    Replies: 3
    Last Post: 12-27-2007, 11:22 PM
  3. Phantom MySQL databases, assistance needed.
    By Garlund in forum Free Hosting
    Replies: 2
    Last Post: 12-12-2007, 08:43 PM
  4. my mysql databases have been removed :(
    By BMX900082 in forum Free Hosting
    Replies: 13
    Last Post: 06-24-2006, 11:17 PM
  5. Have a problem with my forum
    By tikloos in forum Scripts & 3rd Party Apps
    Replies: 43
    Last Post: 01-19-2006, 01:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers