你好,我的表格有问题,我不知道为什么我仍然得到我没有填写整个表格。我看不出我做错了什么,你能帮助我吗?
<?php
if(isset($_POST['submit']))
{
$username = mysqli_real_escape_string($_POST['username']);
$password1 = mysqli_real_escape_string($_POST['password1']);
$password2 = mysqli_real_escape_string($_POST['password2']);
$email = mysqli_real_escape_string($_POST['email']);
if (!empty($username) && !empty($password1) && !empty($password2) && !empty($email) && ($password1 == $password2) )
{
//my code
}
else
{
echo "u wot m8?!";
}
<form id="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" id="username" name="username" placeholder="Your nickname" maxlength="15" /><br />
<div id="check_av"></div>
<input type="password" id="password1" name="password1" placeholder="Your password" /><br />
<input type="password" id="password2" name="password2" placeholder="Retype password" /><br />
<input type="text" id="email" name="email" placeholder="Your email address" /><br />
<input type="submit" id="submit" value="Sign up" name="submit" />
</form>
答案 0 :(得分:4)
我说mysqli_real_escape_string
错误,因为它没有数据库连接,这是必需的第一个参数(mysqli_real_escape_string ( mysqli $link , string $escapestr )
)。
$ php -r 'var_dump( mysqli_real_escape_string("something"));'
Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in Command line code on line 1
Call Stack:
0.0002 130868 1. {main}() Command line code:0
0.0002 130924 2. mysqli_real_escape_string() Command line code:1
NULL
NULL
是empty
因此,要先设置数据库连接,要么在以后设置数据库连接。
故事的道德:enable proper error reporting and catch those errors early & quickly