发送表格后出现问题

时间:2014-01-08 03:06:31

标签: php

你好,我的表格有问题,我不知道为什么我仍然得到我没有填写整个表格。我看不出我做错了什么,你能帮助我吗?

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

1 个答案:

答案 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

NULLempty因此,要先设置数据库连接,要么在以后设置数据库连接。

故事的道德:enable proper error reporting and catch those errors early & quickly