2013-05-29 108 views
0

我試圖使用PHP與XAMPP(Apache和MYSQL)做一個簡單的註冊表單。我目前有一個密碼字段的問題,目前顯示它的輸入爲明文,而不是隱藏它從視圖。回顯密碼輸入字段顯示爲文本

?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>"; 

其中輸入類型不是由於使用了單引號註冊我的問題,莖,而不是雙引號,導致輸入型從字面上並沒有解釋被用作價值?

我將不勝感激任何輸入。 謝謝!

+0

移除!糾正你的代碼是這樣被顯示在輸入爲純文本或提交後..? –

+0

您在表格和提交之前關閉表單標記在表單之外。這將如何工作? – Rahul11

+0

嘗試使用'\「字符嘗試轉義此行'echo'

回答

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>"; 

    } 
+0

斑點 - +1 – allen213

+0

Arghhhh這是一個明顯的錯誤!謝謝你的幫助 –

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 
    }?> 

它不被視爲一個良好的practie呼應HTMLPHP