2017-02-22 50 views
0

我在html中使用php變量。 $userProfile['institute']$userProfile['institute']非空時顯示正確的值。當$userProfile['institute']爲空時,它顯示'/'。這裏可能是什麼問題?在HTML中使用php變量

Institute: <input type="text" name="institute" value=<?php echo $userProfile['institute']?> /><br /> 

回答

3

你缺少一套報價爲你的價值屬性

value="<?php echo $userProfile['institute']?>" 
+1

使用** htmlentities **來防止注入攻擊是一種很好的做法。 <?= htmlentities($ userProfile ['institute'])?> – user2182349

0

你應該加上雙引號像這樣(像你包裹類型和機構的價值屬性)

Institute: <input type="text" name="institute" value=" <?php echo $userProfile['institute']?>" /><br />