• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 318
  • Last Modified:

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!
0
geist62
Asked:
geist62
  • 3
  • 2
  • 2
  • +3
3 Solutions
 
MikkkCommented:
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> ");
}
?>
0
 
RoonaanCommented:
It would be easiest to analyze the differences in the html output rather than the php source code. When you find the html differences you can look for a cause in your php code.

-r-
0
 
geist62Author Commented:
Thanks for the quick responses. I'll try these solutions out and post my findings latte today.

Regards!
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
orbic1Commented:
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
0
 
KhoiNqqCommented:
I needs the rest of page to analyze your case, may be some ' or " breaks your page.
0
 
nplibCommented:
My two cents.
The changing the code to this may help. Although I don't understand how this PHP code could have any impact on CSS
but what the heck.

<?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> ";
}
?>
0
 
MikkkCommented:
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']!="")
 {
...
0
 
KhoiNqqCommented:
@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
0
 
nplibCommented:
can you post the result of your script. What the client see's?

View Source.
0
 
geist62Author Commented:
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!
0
 
nplibCommented:
depends on where you put it.

If you placed it after your CSS entries, and the page broke, they may have never showed up in the final result.
The second posting was for you to post the resulted HTML to the client. Had you done that then, the answer good have been told to you sooner.

P.S. Good rule of thumb. ALL php coding should be done at the absolute top of the page before the <html> tag. Place everything in variables, including html coding, then output it in your html code. via

<?=$variable?>
or <?php
echo $variable;
?>
if you like a lot of typing.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now