Why is my php changing my html in this?

Discussion in 'PHP' started by ScottDB, Jun 13, 2011.

  1. #1
    Hi, I placed my php code into my template and now it is screwing up how the html works. They both work fine by them selves. I know it has to be something stupid and simple that I am overlooking about 30 times. If you want to see what I am talking about you can go here. Click on the members tab to see how it is screwing up.

    <!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">
    <?
    /**
     .
     *
     * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
     * Last Updated: August 26, 2004
     */
    include("include/session.php");
    
    /**
     * displayUsers - Displays the users database table in
     * a nicely formatted html table.
     */
    function displayUsers(){
       global $database;
       $q = "SELECT username,userlevel,email,timestamp "
           ."FROM ".TBL_USERS." ORDER BY userlevel DESC,username";
       $result = $database->query($q);
       /* Error occurred, return given name by default */
       $num_rows = mysql_numrows($result);
       if(!$result || ($num_rows < 0)){
          echo "Error displaying info";
          return;
       }
       if($num_rows == 0){
          echo "Database table empty";
          return;
       }
       /* Display table contents */
       echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n";
       echo "<tr><td><b>Username</b></td><td><b>Level</b></td><td><b>Last Active</b></td></tr>\n";
       for($i=0; $i<$num_rows; $i++){
          $uname  = mysql_result($result,$i,"username");
          $ulevel = mysql_result($result,$i,"userlevel");
          $time   = mysql_result($result,$i,"timestamp");
    
          echo "<tr><td>$uname</td><td>$ulevel</td><td>$time</td></tr>\n";
       }
       echo "</table><br>\n";
    }
    
    ?>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Members</title>
        
        <link rel="stylesheet" type="text/css" href="style/style.css" media="screen" />
    </head>
    <body>
    
    <div id="logo">
    		<h1><a href="#">My Site</a></h1>
    		<p><em> Lets see what we can do</em></p>
    	</div>
    	<hr />
    	<!-- end #logo -->
    	<div id="splash">
    		<div class="col1"><img src="style/images/doship.jpg" width="660" height="300" alt="" /></div>
    		<div class="col2">
    			<blockquote>&#8220;Your team slogan can go here.&#8221;</blockquote>
    		</div>
    	</div>
    	<div id="header">
    		<div id="menu">
    			<ul>
    				<li><a href="index.php">Homepage</a></li>		
    				<li><a href="users.php">Members</a></li>
    				<li><a href="contact.php">Contact</a></li>
    				<li><a href="register.php">Join</a></li>
    				<li><a href="main.php">Login</a></li>
    				<li><a href="process.php">Log Out</a></li>
    			</ul>
    		</div>
    		<!-- end #menu -->
    		
    	</div>
    	<!-- end #header -->
    	<!-- end #header-wrapper -->
    	<!-- start of top left data block ------------------------------------------------------------->
    	
    	<div id="page">
    		<div id="content">
    		  <div class="post">		
    				<div class="entry">
    					<h1>View All Members</h1>
    <font size="5" color="#ff0000">
    <b>::::::::::::::::::::::::::::::::::::::::::::</b></font>
    <font size="4">Logged in as <b><? echo $session->username; ?></b></font><br><br>
    <?
    if($form->num_errors > 0){
       echo "<font size=\"4\" color=\"#ff0000\">"
           ."!*** Error with request, please fix</font><br><br>";
    }
    ?>
    <table align="left" border="0" cellspacing="5" cellpadding="5">
    <tr><td>
    
    <h3>Users Table Contents:</h3>
    <?
    displayUsers();
    ?>
    </td></tr>
    <tr>
    <td>
    <br>
    
    <?
    
    
    ?>
    
    
    				</div>
    		  </div>
    	
    		</div><!-- end #content -->
        <!---Start of side blocks--------------------------------------------------------------->
    		<div id="sidebar">
    			<ul>
    				<li>
    					<h2>Site Info</h2>
    					<ul>
    					<li>
    					<?
    
    
    /**
     * Just a little page footer, tells how many registered members
     * there are, how many users currently logged in and viewing site,
     * and how many guests viewing site. Active users are displayed,
     * with link to their user information.
     */
    echo "</td></tr><tr><td align=\"center\"><br><br>";
    echo "<b>Member Total:</b> ".$database->getNumMembers()."<br>";
    echo "There are $database->num_active_users registered members and ";
    echo "$database->num_active_guests guests viewing the site.<br><br>";
    
    include("include/view_active.php");
    
    ?>
                </li>
                   </ul>
    					</li>
    					
    				<!---Divide between side blocks--------------------------------------------------------------->	
    				<li>
    					<h2>Side Bar 2 </h2>
    					<ul>
    						<li>You can put anything here. You can choose to have the team site stats, or newsletter posted here or just some other information. You can even put pictures here as well.<br><img style="width: 100px; height: 75px;"
     alt=""
     src="http://ezautomaticmoneybusinesses.com/0test/style/images/Dock.jpg">
    
    						</li>
    					</ul>
    				</li>
    				<!---Divide between side blocks--------------------------------------------------------------->
    				<li>
    					<h2>Another Block</h2>
    					<ul>
    						<li>I plan on having a chat on the site and thinking of putting it here. <br>
    					<br>
    					<br>
    					<br></li>
    					</ul>
    				</li>
    			</ul>
    		</div>
    		<!-- end #sidebar -->
    		<div style="clear: both;">&nbsp;</div>
    	</div>
    	<!-- end #page -->
    	<div id="footer">
    	
    		<p>Copyright (c) 2011 Mysite.com. All rights reserved. </p>
    	</div>
    	<!-- end #footer -->
    
    </td></tr>
    </table>
    
    
    </body>
    </html>
    Code (markup):
    Thanks in advance.
     
    ScottDB, Jun 13, 2011 IP
  2. The Webby

    The Webby Peon

    Messages:
    1,852
    Likes Received:
    30
    Best Answers:
    1
    Trophy Points:
    0
    #2
    You can not start session once output on the page has started, so change this:
    
    <!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">
    <?
    /**
     .
     *
     * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
     * Last Updated: August 26, 2004
     */
    include("include/session.php");
    
    PHP:
    To this:
    
    <? include("include/session.php"); ?>
    <!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">
    <?
    /**
     .
     *
     * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
     * Last Updated: August 26, 2004
     */
    
    PHP:
     
    The Webby, Jun 13, 2011 IP
  3. ScottDB

    ScottDB Greenhorn

    Messages:
    95
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    Thanks for the reply. Actually that was a seperate issue and one that I was going to ask next. Took care of the error message I was getting on top of my pages. I figured out that I accidently cut off the </table> from the end of the php code and somehow stuck it down on the bottom. I must have looked at that 20 times and not noticed it.

    Oh the trials and errors of a newbie =)
     
    ScottDB, Jun 13, 2011 IP