如何通过从我的代码附加PHP HTML的另一个页面获取会话变量的值来使Td样式可见?

如何通过从我的代码附加PHP HTML的另一个页面获取会话变量的值来使Td样式可见?

问题描述:

i wanna know to make my td tag style visible an getting value from another php page in the form of session varialbe as my code is define under,

on else condition fron php page i am setting session variable and redirecting to another page as,

else {
session_start();
$_SESSION['Validation'] = 'on';
header("Location: index.html");
}

after then on index.html page in between table tag i am using this script as,

<?php
session_start();
$foo = $_GET['Validation'];
echo $foo;
?>
<tr><td colspan=2><font face="verdana,arial" size="-1" color="red"       style="visibility:hidden">Wrong username or Password</font></td></tr>

how to make td tag style vissible true and it remain hidden if session variable do not get any value ????

Hopes to listen from you ...

Thanks in Advance

use a simple if... then... else condition and make use of your $_SESSION variable to switch those conditions. Create a new variable to hold your current style e.g. $tdStyle = "visibility: hidden;" or $tdStyle = "visibility: visible;" for hiding/showing your td, respectively.

HTML/PHP CODE: [EDIT]

<?php
  ...
  if ($_SESSION['Validation'] == "on") {
     $tdStyle = "visibility: visible;";
  } else  {
     $tdStyle = "visibility: hidden;";
  }
  ...
?>
...
<tr><td style="<?php echo $tdStyle; ?>">Wrong username or Password</td></tr>
...

EDIT: Use index.php not index.html when embedding PHP codes in HTML or your php code will be treated as plain text/html

header("Location: index.php");

NOT

header("Location: index.html");

<?php
session_start();
$foo = $_GET['Validation'];
echo $foo;
?>
<tr>
<td colspan=2>
<font face="verdana,arial" size="-1" color="red" <?php
if (isset($_SESSION['style_visible'])) {
  echo 'style="visibility:visible"';
} else {
  echo 'style="visibility:hidden"';
}
?>
>Wrong username or Password</font></td></tr>

But I think it's wrong

1st Validation

<?php

// make validation
$errors = array();
// if error fill $errors

// store errors in sessions
if (count($errors) > 0) $_SESSION['errors'] = $errors;

2nd form

<?php
session_start();

// show errors
if (isset($_SESSION['errors'])) {
    foreach ($_SESSION['errors'] as $error) {
      echo '<tr><td>'.$error.'</td></tr>';
    }
}

?>