我有以下代码,当您输入值时,变量$username不会回显。
//TODO: SET AUTH TOKEN as random hash, save in session
$auth_token = rand();
if (isset($_POST['action']) && $_POST['action'] == 'Login')
{
$errors = array(); //USED TO BUILD UP ARRAY OF ERRORS WHICH ARE THEN ECHOED
$username = $_POST['username'];
if ($username = '')
{
$errors['username'] = 'Username is required';
}
echo $username; // var_dump($username) returns string 0
}
require_once 'login_form.html.php';
?>login_form是这样的:
<form method="POST" action="">
<input type="hidden" name="auth_token" value="<?php echo $auth_token ?>">
Username: <input type="text" name="username">
Password: <input type="password" name="password1">
<input type="submit" name="action" value="Login">
</form>身份验证令牌部分并不重要,它只是当我在用户名文本框中键入一个值并按下登录按钮时,用户名不会回显,var_dump返回字符串(0),而print_r则为空。
发布于 2010-12-25 12:29:46
愚蠢的错误
if ($username = '') <-- this is an assignment应该是这样的
if ($username == '') <-- this is comparisonhttps://stackoverflow.com/questions/4529288
复制相似问题