I am trying to show two hidden <div> (lines 54 & 55) depending on the value of a session variable.
I know the "if" statement is working because the alert tests I have do show when the code is run.
The "Viewing all whose payment has NOT been confirmed." should display if the condition is false while the "Viewing all who have been confirmed." should display if the condition is true. However, neither phrase is displayed. Can anyone help me out?

A snippet of my code follows.

<?php 
	session_start();


if(isset($_SESSION['validUser']))
	{
	if ($_SESSION['validUser']!= "True") 
		die("You are not allowed here!!");
	} 
else
	die("You are not allowed here!");
		

	if ($_SESSION['filter'] <> 'N') {
	echo "Hello A1";
		?>
		<script language="javascript">
		alert("Hello 1");		

			document.getElementById("tel1").style.display = "block";
		
		</script>
		<?
	} else {
	echo "Hello A2";	
		?>
		<script language="javascript">
		alert("Hello 2");		

			document.getElementById("tel2").style.display = "block";
		
		</script>
		<?
	}

	
if (isset($_POST['update'])) {

// Save the changes
	$currentrow = $_SESSION['currentrow'];

// (more php code not shown)
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test</title>

</head>
<body >
	<form id="orderForm" method="post" >
		
		<div id="tel1" style="display:none">Viewing all whose payment has NOT been confirmed.</div>
		<div id="tel2" style="display:none">Viewing all who have been confirmed.</div>
		
		<fieldset>
		<legend>About You</legend>
	<div class="grid_3">										
		<input type="text"  size="30" maxlength="30" tabindex="1" name="fname" id="fname" />
    </div><!-- end .grid_3 -->
    
    		<div class="clearb"></div>
    		
  <div class="grid_2">
	<input type="text"  size="30" maxlength="30" tabindex="2"  name="lname" id="lname" />
    </div><!-- end .grid_2 -->

</form>

</body>
</html>

Hello my friend, hope this may help you.
Pardon my english if any mistake.
First thing after 'session_start()', you must assign 'true' or 'false' to the session variable as
$_SESSION['validUser']="True";

I think your problem is not in the code. It is in the sequence of execution of php and html code.
Try to cut and paste the php code below the </HTML> tag (below the page).
Because you are displaying the two 'div' 'tel1' and 'tel2' as 'none', so your php and java script code might be change the display to 'block' but after executing the php code your html code again changes that to 'none'.

Here your updated code
Good Luck

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test</title>

</head>
<body >
    <form id="orderForm" method="post" >

        <div id="tel1" style="display:none">Viewing all whose payment has NOT been confirmed.</div>
        <div id="tel2" style="display:none">Viewing all who have been confirmed.</div>

        <fieldset>
        <legend>About You</legend>
    <div class="grid_3">                                     
        <input type="text"  size="30" maxlength="30" tabindex="1" name="fname" id="fname" />
    </div><!-- end .grid_3 -->

            <div class="clearb"></div>

  <div class="grid_2">
    <input type="text"  size="30" maxlength="30" tabindex="2"  name="lname" id="lname" />
    </div><!-- end .grid_2 -->

</form>

</body>
</html>

<?php 
    session_start();
$_SESSION['validUser']="True";

if(isset($_SESSION['validUser']))
    {
    if ($_SESSION['validUser']!= "True") 
        die("You are not allowed here!!");
    } 
else
    die("You are not allowed here!");


    if ($_SESSION['filter'] <> 'N') {
    echo "Hello A1";
        ?>
        <script language="javascript">
        alert("Hello 1");       

            document.getElementById("tel1").style.display = "block";

        </script>
        <?
    } else {
    echo "Hello A2";    
        ?>
        <script language="javascript">
        alert("Hello 2");       

            document.getElementById("tel2").style.display = "block";

        </script>
        <?
    }


if (isset($_POST['update'])) {

// Save the changes
    $currentrow = $_SESSION['currentrow'];

// (more php code not shown)
}
?>

Instead of having all the PHP in the head, you could add the if statement inline:

<?php 
	session_start();


if(isset($_SESSION['validUser']))
	{
	if ($_SESSION['validUser']!= "True") 
		die("You are not allowed here!!");
	} 
else
	die("You are not allowed here!");
	
if (isset($_POST['update'])) {

// Save the changes
	$currentrow = $_SESSION['currentrow'];

// (more php code not shown)
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test</title>

</head>
<body >
	<form id="orderForm" method="post" >
		


	<?php
          if ($_SESSION['filter'] <> 'N')
          {
	    echo "<div id=\"tel1\" style=\"display:none\">Viewing all whose payment has NOT been confirmed.</div>";
	  }
          else
          {
	    echo "<div id=\"tel2\" style=\"display:none\">Viewing all who have been confirmed.</div>";
	  }
        ?>
		
		<fieldset>
		<legend>About You</legend>
	<div class="grid_3">										
		<input type="text"  size="30" maxlength="30" tabindex="1" name="fname" id="fname" />
    </div><!-- end .grid_3 -->
    
    		<div class="clearb"></div>
    		
  <div class="grid_2">
	<input type="text"  size="30" maxlength="30" tabindex="2"  name="lname" id="lname" />
    </div><!-- end .grid_2 -->

</form>

</body>
</html>

Thanks mahavir123!

Your suggestion worked. But instead I just moved the If statement section to the bottom as I have other statements that need to get some information before the form is loaded.

I should have thought of moving the test to the bottom. It makes sense, as the hidden <div>'s have not been created yet, so the code being at the top cannot make them visible.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.