0

我正在尝试使用带有 XAMPP(Apache 和 MYSQL)的 php 制作一个简单的注册表单。我目前的密码字段存在问题,该字段当前将其输入显示为明文,而不是从视图中隐藏它。

?php
$regfields=array("remail"=>"Email","remail2"=>"Re-enter     Email","rusername"=>"Username","rpassword"=>"Password","rpassword2"=>"Re-enter Password","rbiz"=>"BizName","rdesc"=>"Desc");
?>

<html>
<body>
<h3>Registration</h3>
<form action="Login.php" name="RegisterForm" method="post" >
<table border="0">

<?php

if(isset($errormsg))
{
    echo"$errormsg";
}

foreach($regfields as $field=>$value)
{

    if($field!=="rdesc")
    {
        echo"<tr>";
        echo"<td>";
        echo"<label for='$field'>$value: </label>";
        echo"</td>";
        echo"<td>";
        echo"<input type='text' name='$field' size='40' maxlength='50' />    </td></tr>";

    }
    else if($field=="remail"||$field=="remail2")
    {
        echo"<tr>";
        echo"<td>";
        echo"<label for='$field'>$value: </label>";
        echo"</td>";
        echo"<td>";
        echo"<input type='text' name='$field' size='40' maxlength='50' /></td></tr>";

    }
    else if($field=="rpassword"||$field=="rpassword2")
    {
        echo"<tr>";
        echo"<td>";
        echo"<label for='$field'>$value: </label>";
        echo"</td>";
        echo"<td>";
        echo"<input type='password' name='$field' size='40' maxlength='50' /></td></tr>";

    }
    else
    {
        echo"<tr>";
        echo"<td>";
        echo"<label for=$field>$value: </label>";
        echo"</td>";
        echo"<td>";
        echo"<input type='text' name='$field' size='300' maxlength='300' style='width:400px;height:100px; \n'/>";
        echo"</td>";
        echo"</tr>";
    }
}

?>
</form>
</table>
<input type="submit" name="Button" value="Register" />
</body>
</html>

我怀疑我的问题源于这条线

echo"<input type='password' name='$field' size='40' maxlength='50' /></td></tr>";

由于使用了单引号,输入类型没有注册,而不是双引号导致输入类型被逐字解释而不被用作值?

我将不胜感激对此的任何意见。谢谢!

4

2 回答 2

2

哦,看看这个

下面的代码一直执行,除非该字段是 rdesc. !因此,通过删除来更正您的代码if($field!=="rdesc")

  if($field!=="rdesc")
    {
        echo"<tr>";
        echo"<td>";
        echo"<label for='$field'>$value: </label>";
        echo"</td>";
        echo"<td>";
        echo"<input type='text' name='$field' size='40' maxlength='50' />    </td></tr>";

    }
于 2013-05-29T13:04:16.280 回答
1

如果你发现单引号和双引号的用法令人困惑,试试这个

<?php
else if($field=="rpassword"||$field=="rpassword2")
    {?>

<tr>
    <td>
        <label for="<?php echo $field?>"><?php echo $value?>: </label>
        </td>
        <td>
        <input type="password" name="<?php echo $field?>" size='40' maxlength='50' /></td></tr>
<?php
    }?>

它不被认为是一个很好的做法来回响HTML内部PHP

于 2013-05-29T12:49:52.787 回答