Solved

was working now not :S echo in html

Posted on 2011-03-06
6
271 Views
Last Modified: 2012-05-11
i have this div that is positioned nice on my banner
but the php echo is not echoing where the div is positioned on the page. its echoing at the very top of the page even though i put the php in the div.


here is the code:

<?php
session_start();
if(isset($_POST['submit1'])) {
logout();
}
?>

<div id="apDiv6"><!-- logout echo here-->
<?php

function logout()
{

      if ($_SESSION['u_name'])
      {
            session_destroy();
      echo "You've been logged out.";}
      else{
            echo "You where not logged in!";
            }        
}
?>
</div>

<div id="two"><!-- logout button here-->

<form action="<?=$_SERVER['PHP_SELF'];?>" method="POST">
<table width="65" border="0" cellpadding="1" cellspacing="3" class="table1">
<td width="57">
<input type="submit" name="submit1" value="Log out"></td>
</table>
</form>
</div>

#apDiv6 {/*css postitions for my echo*/
      position:absolute;
      width:458px;
      height:45px;
      z-index:4;
      left: 183px;
      top: 61px;
}
i allso have some more css for the button here to. what i show here is just a part of my code

so how come the echo is not displayed where i placed the div?
i just want my echo to be displayed in the place i want to position it at :( was working a few hours ago.
0
Comment
Question by:helpchrisplz
  • 4
  • 2
6 Comments
 
LVL 4

Expert Comment

by:florjan
ID: 35045523
      if ($_SESSION['u_name'])
      {
            session_destroy();
      echo "You've been logged out.";}
      else{
            echo "You where not logged in!";
            }    

Open in new window

 if ($_SESSION['u_name']) {
	session_destroy();
	echo "You've been logged out.";}
else{
	echo "You where not logged in!";
}    

Open in new window


I have made spacing proper. I had same problem yesterday, hope it helps.
0
 
LVL 1

Author Comment

by:helpchrisplz
ID: 35045817
i try that and nothing changes
0
 
LVL 4

Expert Comment

by:florjan
ID: 35046412
What if you add <p> and </p>.
if ($_SESSION['u_name']) {
        session_destroy();
        echo "<p>You've been logged out.</p>";
}else{
        echo "<p>You where not logged in!</p>";
}  

Open in new window

Also I have rewrote the code and made it nicer if you're interested (you want to put echo after the logout button right?).
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 4

Accepted Solution

by:
florjan earned 500 total points
ID: 35046461
Here's the rewritten code.  
<?php
session_start();
if(isset($_POST['submit1'])) {
	logout();
}

/* This function checks if $_SESSION['u_name'] is open and 
 * if it is it destroys(deletes) the session and writes 
 * something into variable $logoutmessage, otherwise
 * it writes something else into variable $logoutmessage.
 * Global indicates that $logoutmessage can also be used 
 * outside of function. */
function logout() {
	global $logoutmessage;
	if ($_SESSION['u_name']) {
		session_destroy();
		$logoutmessage = "<p>You've been logged out<p>";
	} else {
		$logoutmessage = "<p>You've been logged out<p>";
	}        
}
/* If the logoutmessage isn't set it's null */
if (!isset($logoutmessage)) {
	$logoutmessage = "";
}
/* Now we echo everything we want (EHTML marks it as html instead 
 * plain like in normal echo and also we can use both " and ')*/
echo  <<<EOHTML
<div id="two"><!-- logout button here-->
<form action="{$_SERVER['PHP_SELF']}" method="POST">
<table width="65" border="0" cellpadding="1" cellspacing="3" class="table1">
<td width="57">
<input type="submit" name="submit1" value="Log out"></td>
</div>
</table>
</form>
<div id="apDiv6"><!-- logout echo here-->
$logoutmessage
</div>
EOHTML;
?>

Open in new window

0
 
LVL 4

Expert Comment

by:florjan
ID: 35047184
Ups a mistake on line 19 of code in my last post. Should be You were not logged in instead of You've been logged out
0
 
LVL 1

Author Closing Comment

by:helpchrisplz
ID: 35058169
had to change it a bit but works thx
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mysqli_connect error on wamp but not on remote server 8 37
php56-php-mcrypt for rhel7 php56 1 55
Redirect 301 from one address  to another 5 26
Ajax and PHP 9 30
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question