[web] Problem with PHP & Firefox

Started by
16 comments, last by obi-wan shinobi 18 years, 3 months ago
I have written a function to pull info from a MySQL database, sort it in alphabetical order, and display it as a series of html links. I include this .php file in another .php file and call the function that does the displaying of links. Also, I use these XHTML lines at the very top of the main .php file :
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
This is for XHTML 1.0 compliance. In addition, I use the <link> tag within the <head> tag to import a stylesheet that works fine between both browsers, even more so with the XHTML lines above. The problem is that while the function works in IE as intended, Firefox seems to ignore calling the function at all no matter where the call is placed in the file (after the include statement of course). The include statement is within the <body> tag. I've googled for this problem and didn't seem to get anything relevant. So, does anyone here know what the problem could be?
Advertisement
The situation you stated is virtually impossible. PHP is a serverside scripting language. There's no way a browser can choose if it does or does not trigger PHP scripts. Would you mind showing us the files? Also, check if the links can be output as HTML. (Look in the page source for the data) If they're displayed, then it's probably your CSS's fault (black text on black background?)

Good luck!
Here's the files:

The code to list the links:
<html><head></head><body> <?php  function onsitelist() {   echo 'onsitelist function called.';   $sql = mysql_connect('localhost','user','passwd');   if(!$sql)  	return mysql_errno($sql);   $db = mysql_select_db('test',$sql);   if(!$db)	return mysql_errno($db);   $query = mysql_query("SELECT sitename, url FROM weblinks ORDER BY sitename");   if(!$query)	return mysql_errno($query);   echo '<br>';   while($index = mysql_fetch_array($query, MYSQL_NUM)) {    $name = $index[0];    $url = $index[1];    printf("<a href=%s>%s</a><br>", $url, $name);   }  } ?></body></html>


The css code:
input {}input.msg {}div {}div.leftinfo {left:0px;top:235px;width:190px;height:375px;	position:absolute;overflow:scroll;border-style:none;border-width:5px;	padding-top:5px;padding-bottom:5px;padding-left:5px;padding-right:5px}div.midinfo {left:200px;top:235px;width:590px;height:375px;	position:absolute;overflow:scroll;border-style:none;border-width:0px;	padding-top:5px;padding-bottom:5px;padding-left:5px;padding-right:5px}div.rightinfo {left:800px;top:235px;width:190px;height:375px;	position:absolute;overflow:scroll;border-style:solid;border-width:0px;	padding-top:5px;padding-bottom:5px;padding-left:5px;padding-right:5px}div.lefttab {position:absolute;left:0px;top:200px;width:190px;height:25px;background-color:#ff0000;border-style:double;	border-color:black;border-width:5px;color:white;font-weight:bold;padding-left:0px;padding-right:0px}div.midtab {position:absolute;left:200px;top:200px;width:590px;height:25px;background-color:#00ff00;border-style:double;	border-color:black;border-width:5px;color:black;font-weight:bold;padding-left:0px;padding-right:0px}div.righttab {position:absolute;left:800px;top:200px;width:190px;height:25px;background-color:#0000ff;border-style:double;	border-color:black;border-width:5px;color:white;font-weight:bold;padding-left:0px;padding-right:0px}div.overlay {}


The main php file that links to both:
<!DOCTYPE htmlPUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html><head><title>Webpage beta 0.1</title><link rel="StyleSheet" href="front.css" type="text/css" /></head><body><?php if((include 'ecl_listlinks.php') == 'OK') {  echo 'File included!'; }?><div class="lefttab"><center>On-Site Links</center></div><div class="leftinfo">About Me<br />About The Site<br />Archive<br>FAQ<br>Guestbook<br>Pics n' Such<br>Recent Posts:<br> #1<br> #2<br> #3<br> #4<br></div><div class="midtab"><center>Current Post</center></div><div class="midinfo">All the news that's fit to print and then some...</div><div class="righttab"><center>Off-Site Links</center></div><div class="rightinfo"> <?php  onsitelist(); ?></div></body></html>


This is for a blog that I'm planning on starting soon. As far as the CSS, I've seen the stuff display just fine in IE. In Firefox however, nothing is shown. I even tried to highlight the entire page just to make sure the text color didn't match the background color.
You do realise, that because you're including a file which already has its own <html> and </html> elements in, there will be an empty body before the one with the data in.

If you use "view source", you should see this error. Firefox is displaying the page correctly, as the body is entirely empty, followed by some rubbish which it is ignoreing.

IE is displaying the page incorrectly because it is showing stuff after </body>

However, the page is badly formed so it doesn't really matter anyway.

You can only have one <html> and <body> element.

Mark
Quote:Original post by markr

You can only have one <html> and <body> element.

Mark


Actually since this is XHTML Strict, you can only have one block-level tag, meaning that block tags inside of block tags is also a no-no, and you'll probably want to check that out. IE 6 doesn't have a true understanding of XHTML due to it being as old as it is, Firefox has a lot of the underpinnings for it, and trust me, XHTML Strict is well, strict.

Of course, if you've still got two body/head tags, that's going to throw a DOM error before anything else will, and not only will the code not validate, it won't even begin to display right in a recent browser.
I see you're also missing closing tags for your br elements.

You're not XHTML compliant until this tool says you are. It also helps to get a text editor that will validate while you type (if you get the XML plugin).
D'oh. Didn't mean to post as AP.

See these links:
W3 validator
jEdit.
Free Mac Mini (I know, I'm a tool)
Quote:Original post by markr
You do realise, that because you're including a file which already has its own <html> and </html> elements in, there will be an empty body before the one with the data in.


I never thought of that. Thanks for bringing it up. I'll remove the <html> tags from the included .php file and try it again later on today. I suspected Firefox was doing something right considering that it apparently automatically shows pages in xhtml. I say this since removing the xhtml stuff at the top doesn't affect Firefox, but IE is affected.

Quote:I see you're also missing closing tags for your br elements.

I know, but I was following the xhtml tutorial at www.w3schools.com and that's how it's done there.
Okay. I've removed the <html>, <head>, and <body> tags from the included .php file. After that, I removed the center tags and shortened the include line in the main .php file and the validator accepted it. IE still displays it fine and Firefox still refuses to show any PHP. Not even inline PHP works with Firefox; all PHP seems to be ignored there. Maybe it's a configuration error?
Configuration errors can't make that happen. There is bound to be something seriously wrong with your HTML.

PHP should not be shown anyway, it should be executed.

Either post the generated HTML somewhere, or make the page publicly available so we can look at it. I'm sure there's a fairly serious problem.

Depending on what content type you use, Mozilla *MAY* use its XML parser to parse XHTML (It usually does not). This will cause the page to fail if it is not well-formed - although the error should be large and obvious.

Mark

This topic is closed to new replies.

Advertisement