Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional HTML output not working

Status
Not open for further replies.

wsimmonds

Programmer
Aug 3, 2002
27
0
0
GB
Hi all,

Having a slight problem with my development machine. I've just upgraded to PHP 5.2.1 (can't remember previous version)..

I am trying to do some template-based work, and for this I like to be able to edit my HTML within Dreamweaver/visual software.

My problem is that a statement that previously worked now will not:

<? if(1 = 1) { ?>
1 is 1!
<?} else { ?>
1 is not 1!
<? } ?>

That outputs that 1 is 1, and 1 is not 1 - totally ignoring the conditional brackets. This used to work for me - I've been searching and searching and haven't yet found a configuration option. Am I missing something obvious here?

It's not urgent though, as for now I'll just put my bits of code into files and then call include() within PHP. But I would like to find out why it's suddenly stopped working..
 
A few things.

First, do you mean to use the assigment operator (=) in the condition of your if-statement? I generally use the comparison operator (==).

I also think that switching back and forth between HTML output mode and PHP interpreted mode reduces readability.

What does

Code:
<?
if(1 == 1)
{
   print '1 is 1!';
}
else
{
   print '1 is not 1!';
}
?>


Anyway, can you better describe what is happening on your system? I would expect the above script to always output [tt]1 is 1[/tt].



Want the best answers? Ask the best questions! TANSTAAFL!
 
Try using == (double equal sign) instead of = (single equal sign) in your if statement. Why are you comparing 1 to 1 anyway? That will always equate to true, anyway.
 
Sorry guys that was a typo! But I had actually used the comparison operator and not assignment within the code.

That was me trying to just re-produce it.. I should have copied and pasted!

This is the strange thing, as it works on several other development/production systems - just not my own machine.

The problem is it's always outputting anything not contained within the <?/?> code area.

The real use of this is for something like:

<?
if($_GET['invalidLogin'] == 1) {
?>
HTML HERE TO SAY INVALID LOGIN
<?
}
?>

And it's always outputting! But the code below, of course, works fine and outputs nothing unless invalidLogin is indeed set to 1.

<?
if($_GET['invalidLogin'] == 1) {
echo "HTML HERE TO SAY INVALID LOGIN";
}
?>
 
Thanks for the respones so far I meant to add to the previous message.. I have actually been known to use = instead of == before in code.. the perils of having to also work with VB6 sometimes!
 
print the value of the GET superglobal elements to debug.
Code:
echo '<pre>'.print_r($_GET, true).'</pre>';

also you might take a look at sleipnir's faq on debugging techniques.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top