我已经使用php验证制作了这个表单,然后尝试在输入后做一个红色边框,以防在提交后输入中出现错误,但是当我点击提交时,所有输入都会消失,除了用户名并且风格不起作用,代码的形成有问题吗?
<?php foreach ($return as $user) {
$avatar = $decoding->response->players[0]->avatar;
?>
<td id="addme"><img src="<?php echo $avatar; ?>" width="32" height="32"></td>
<td><?php echo $user->DisplayName; ?></td>
<td><?php echo $user->SteamID; ?> <a href="http://steamcommunity.com/profiles/<?php echo $user->SteamID; ?>/" target="_blank"><span class="glyphicon glyphicon-new-window" id="gotosteamprofile"></span></a></td>
<td><?php
$ipredc = substr($user->Address, 0, -6);
echo $ipredc; ?></td>
<td><?php
$toconver = $user->ConnectedSeconds;
$hours = floor($toconver / 3600);
$mins = floor($toconver / 60 % 60);
$secs = floor($toconver % 60);
$timeFormat = sprintf('%02d:%02d:%02d', $hours, $mins, $secs);
echo $timeFormat;
?></td>
</tr>
<?php
}
?>
答案 0 :(得分:0)
我认为你只是没有结束你的样式标签中的引号。
定义$ uErr和$ pErr时,你错过了一个'。
定义$ uErr
$uErr = "style='border: 2px solid red'";
和$ pErr
$pErr = "style='border: 2px solid red'";
请注意,我添加了'在最终之前'
答案 1 :(得分:0)
您可以使用布尔标志变量,如下所示:
<?php
if (isset($_POST['submit'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$hasError = FALSE;
if (!preg_match("/^[0-9a-zA-Z_]{4,}$/",$username) || empty($username) {
$usernameStyle = 'style="border: 2px solid red"';
$hasError = TRUE;
}
if (!preg_match("/^.*(?=.{8,})$/",$password) || empty($password)) {
$passwordStyle = 'style="border: 2px solid red"';
$hasError = TRUE;
}
if (!$hasError) {
echo "Executed";
}
}
?>