0

Hi,

I have some PHP code in a project which if a user is logged in the in will display the username and other options and if the user is a guest it wont.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Home</title>
</head>
<body>

<!-- HTML Layout here -->

<?php
if($session->logged_in){
echo "Welcome $user"
  ."<a href="index.php">Home</a><br>"
  ."<a href="forums.php">Forums</a><br>"
  ."<a href="downloads.php">Downloads</a><br>"
  ."<a href="profile.php">Profile</a><br>"
  ."<a href="settings.php">Settings</a><br>";
}
else {
echo "Welcome Guest"
  ."<a href="index.php">Home</a><br>"
  ."<a href="forums.php">Forums</a><br>"
  ."<a href="downloads.php">Downloads</a><br>";
}
?>
</body>
</html>

now even though this works my project needs to be validated but the validator fails because of the php coding it says the following

#  Error  Line 1208, Column 83: character data is not allowed here

…strong>$session->username</strong>  <span style='font-size: 80%;'></span></li>'

You have used character data somewhere it is not permitted to appear. Mistakes that can cause this error include:

    * putting text directly in the body of the document without wrapping it in a container element (such as a <p>aragraph</p>), or
    * forgetting to quote an attribute value (where characters such as "%" and "/" are common, but cannot appear without surrounding quotes), or
    * using XHTML-style self-closing tags (such as <meta ... />) in HTML 4.01 or earlier. To fix, remove the extra slash ('/') character. For more information about the reasons for this, see Empty elements in SGML, HTML, XML, and XHTML.

is there a way i can bypass this part of the coding or can i change something in the code which the validator will accept.

2
Contributors
9
Replies
10
Views
7 Years
Discussion Span
Last Post by redous
0

strong>$session->username</strong> <span style='font-size: 80%;'></span></li>'

The bit that's wrong is the use of single quotes instead of double quotes in HTML.

The "span" tags should read:

<span style="font-size: 80%;"></span>
0

The bit that's wrong is the use of single quotes instead of double quotes in HTML.

The "span" tags should read:

<span style="font-size: 80%;"></span>

ive tried all ways of putting this part of the code

.'<strong>$session->username</strong> <span style='font-size: 80%;'></span></li>'
."<strong>$session->username</strong> <span style=\"font-size: 80%;\"></span></li>"
.'<strong>$session->username</strong> <span style="font-size: 80%;"></span></li>'

none of these work the middle one actually throws up 5 more validator errors. Am i using the wrong doctype due to the page having php in.

0

i originally thought it was because the </li> was there without the beginning <li> but that again throws more errors up and leaves my site all messed up.

0

ive tried all ways of putting this part of the code

.'<strong>$session->username</strong> <span style='font-size: 80%;'></span></li>'
."<strong>$session->username</strong> <span style=\"font-size: 80%;\"></span></li>"
.'<strong>$session->username</strong> <span style="font-size: 80%;"></span></li>'

none of these work the middle one actually throws up 5 more validator errors. Am i using the wrong doctype due to the page having php in.

Can you show us the code which includes that line? THe original code you posted does not contain the <span style> code.

0
<?php
if($session->logged_in){
echo "<li class='userbar_row_title'>"
	."<strong>$session->username</strong>  <span style=\"font-size: 80%;\"></span></li>"
	."<li class='userbar_row'><a class='userbar_row content' href='../userinfo.php?user=$session->username'>"
	."<img class='userbar_row_large_icon' src='modules/userbar/images/awards.png' alt=''>Profile</a></li>"
	."<li class='userbar_row'><a class='userbar_row content' href='#'>"
	."<img class='userbar_row_large_icon' src='modules/userbar/images/games.png' alt=''>Mail <span>(8)</span></a></li>"
	."<li class='userbar_row'><a class='userbar_row content' href='../useredit.php' title='Settings'>"
	."<img class='userbar_row_large_icon' src='modules/userbar/images/edit.png' alt=''>Edit Profile</a></li>"
	."<li class='userbar_row'><a class='userbar_row content' href='../process.php' title='Logout'>"			
	."<img class='userbar_row_large_icon' src='modules/userbar/images/logout.png' alt=''>Logout</a></li></ul>"
	."<a class='userbar_link' href='../userinfo.php?user=$session->username' title='My Profile'>"
	."<img src='images/users/thumbnails/$session->username.jpg' class='userbar_photo' style='position: absolute; top: 0px; left: 0px;' alt=''>"
	."<div class='userbar_caption' style='padding-left: 26px;'>$session->username</div></a></div>"
	."<div class='userbar_right_line'></div>"
0

That code looks good. Verify in your "View Source" (in the browser) that it comes out as:

<span style="font-size: 80%;"></span></li>
0

yea it does but it still flags in xhtml validator has being wrong is it something to do with the validator itself not liking php code.

0

The PHP code should not display to the browser. Your query as to why the XHTML validator is failing your code is not really a PHP question but more an HTML question.

I suggest you post the entire HTML code (copy/pasted from the browser View Source). Some people here may be able to help you work out why the XHTML validator doesn't like your code, but a better forum would be the HTML and CSS one here: http://www.daniweb.com/forums/forum143.html

0

okay for some wierd reason i gave up on solving the problem last night this morning i logged on looked at it again and still there was a problem. Again i had enough and logged out after changing a few things (nothing to do with the line in question) but was still getting a error i then retried just and the error messaged has gone and all is validated i have no idea what i did (or who did) but its all clear now.

Case closed

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.