Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi there

am trying to create a welcome page for when a member register/login but i dont quite know where the error is. i know there is an error there somewhere but as usual, finding my errors in one of my major fault. I am doing it in php

the opening tag in php is red as it supposed to be but the closing tag is black which is not supposed to be among other codes in the form

I put it in a html form but it is saved as a php. the closing tag of the body and html element are black in color which i dont think it should be. it should be blue but somewhere in the codes is an error, can someone explain to me why it is like that. trying looking through the codes but cant find it, i even past it thru a php validator.

here is the codes that I have tried.

What I have tried:

PHP
<?php
  session_start();
  if(isset($_SESSION['user'])) {
    header('Location:login.php');
  }
?>

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11.dtd">

<html xmlns="http:www.w3.org/1999/xhtml"xml:lang="en" lang="en">

	<head>
		<title> Welcome - <?php echo <$_SESSION['user']; ?></title>
	</head>
	<body>
		
		<?php
		
		
			<h2> Welcome!!!</h2>
			
			<option value="realname"><?php echo $_SESSION['firstname']. ' ' .$_SESSION['lastname']?></option>

		?>
	
	
	</body>
</html>
Posted
Updated 30-Apr-18 9:46am
v2

1 solution

PHP
<?php
  session_start();
  if(isset($_SESSION['user'])) {
    header('Location:login.php');
  }
?>

<?xml version="1.0" encoding="UTF-8"?> -- Why this line?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11.dtd"> -- Use simple DOCTYPE for HTML5
<html xmlns="http:www.w3.org/1999/xhtml"xml:lang="en" lang="en"> -- namespace is not neccesary at all
	<head>
		<title> Welcome - <?php echo <$_SESSION['user']; ?></title>
	</head>
	<body>
		<?php -- opening for inline PHP
			<h2> Welcome!!!</h2> -- it should be echo as it is PHP code area here
			<option value="realname"><?php echo $_SESSION['firstname']. ' ' .$_SESSION['lastname']?></option> -- it is still PHP code area, so no place for HTML. You also have here a nested inline PHP, that not supported anyway
		?> -- closing for inline PHP
	</body>
</html>


See the comments...
Except those cosmetic things around DOCTYPE all you have to do is remove the external PHP inline directive...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900