如何通过从另一个页面我的代码附加的PHP HTML中获取会话变量的值,使Td样式可见?
我想知道如何使我的td标记样式可见,以会话变量的形式从另一个php页面获取值,因为我的代码在下面定义 在php页面的else条件下,我设置会话变量并重定向到另一个页面,如下所示:如何通过从另一个页面我的代码附加的PHP HTML中获取会话变量的值,使Td样式可见?,php,html,css,validation,Php,Html,Css,Validation,我想知道如何使我的td标记样式可见,以会话变量的形式从另一个php页面获取值,因为我的代码在下面定义 在php页面的else条件下,我设置会话变量并重定向到另一个页面,如下所示: else { session_start(); $_SESSION['Validation'] = 'on'; header("Location: index.html"); } 之后,在index.html页面的表标记之间,我使用这个脚本作为 <?php session_start(); $foo = $_G
else {
session_start();
$_SESSION['Validation'] = 'on';
header("Location: index.html");
}
之后,在index.html页面的表标记之间,我使用这个脚本作为
<?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>
错误的用户名或密码
如果会话变量没有得到任何值,如何使td标记样式可视为真并保持隐藏
希望能听到你的声音
提前感谢如果。。。然后。。。else条件,并使用$\u会话变量切换这些条件。创建一个新变量以保存当前样式,例如分别用于隐藏/显示td的
$tdStyle=“可见性:隐藏;”
或$tdStyle=“可见性:可见;”
HTML/PHP代码:[编辑]
<?php
...
if ($_SESSION['Validation'] == "on") {
$tdStyle = "visibility: visible;";
} else {
$tdStyle = "visibility: hidden;";
}
...
?>
...
<tr><td style="<?php echo $tdStyle; ?>">Wrong username or Password</td></tr>
...
我不明白,你能举个例子吗?@SyedRaza同样,不要使用index.html
,而是使用index.php
,因为你在html
代码中编写php
。否则,嵌入的PHP代码将永远不会被PHP引擎解释。哼哼,为什么按照您告诉我的那样做后我不明白?好的,我尝试了。当我第一次加载此页面而没有从任何其他页面“undefined variable$-session”重定向到它时,我会出错?您是否使用
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>
<?php
// make validation
$errors = array();
// if error fill $errors
// store errors in sessions
if (count($errors) > 0) $_SESSION['errors'] = $errors;
<?php
session_start();
// show errors
if (isset($_SESSION['errors'])) {
foreach ($_SESSION['errors'] as $error) {
echo '<tr><td>'.$error.'</td></tr>';
}
}
?>