Link to home
Start Free TrialLog in
Avatar of geist62
geist62

asked on

PHP code breaks CSS styling of forms

When I include the following php code at the top of my web page or call it from an external file it messes up the  formatting of forms. All other css elements remain in tact.  The text on my forms become extra large and input boxes stretch across the page.  What's up?  The php code is as follows:

<?php
if(isset($_SESSION['username']) && $_SESSION['username']!="")
{
  echo("<a href='logout.php'>Logout</a> ");
  echo($_SESSION['username']);// displays username
}
else
{
  echo("<a href='login.php'>Login</a> ");
}
?>

Thanks!
Avatar of Mikkk
Mikkk

Try with this: separate the isset from the comparison in order to not to get a warning also if the object is not set

<?php
if(isset($_SESSION['username']))
{
 if ($_SESSION['username']!="")
 {
  echo("<a href='logout.php'>Logout</a> ");
  echo($_SESSION['username']);// displays username
 }
 else
 {
   echo("<a href='login.php'>Login</a> ");
 }
}
else
{
 echo("<a href='login.php'>Login</a> ");
}
?>
ASKER CERTIFIED SOLUTION
Avatar of Roonaan
Roonaan
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of geist62

ASKER

Thanks for the quick responses. I'll try these solutions out and post my findings latte today.

Regards!
Hi,

You have some brackets that you don't need!

  echo("<a href='logout.php'>Logout</a> ");
  echo($_SESSION['username']);// displays username

should be:

  echo "<a href='logout.php'>Logout</a>";
  echo $_SESSION['username']; // displays username
I needs the rest of page to analyze your case, may be some ' or " breaks your page.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm pretty sure that the problem is this line
if ((isset($_SESSION['username'])) && ($_SESSION['username'] != ""))

Because here, php core, check both variables, and if $_SESSION['username'] is not set, it maybe echos a warning
because of this, i suggest to transform it, for example to:
if(isset($_SESSION['username']))
{
 if ($_SESSION['username']!="")
 {
...
@Mikkk: && is a short circuit AND logic, so if the first condition no satify, it not check the second condition, that condition can be translate: if $_SESSION['username'] is set then if $_SESSION['username'] is not blank then do the following
can you post the result of your script. What the client see's?

View Source.
Avatar of geist62

ASKER

Thanks folks! Does this make sense:  I placed the php script in the  header section of my web page and that stopped the formatiing of my form from getting messed up. As mentioned the php code shouldn't have any impact on the CSS.

I tried the suggestion on chaning the php code (removing the brackets, etc.), but this had no effect.  It just seems odd that this simple piece of PHP code would change my CSS.

Regards!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial