0

Hello I have a problem with my form, I don't know why I still get that I didn't fill the whole form. I can't see what I am doing wrong, can you help me?

<?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>
Tun Zarni Kyaw
  • 2,099
  • 2
  • 21
  • 27
  • the error is "u wot m8?!" so it says that I didn't fill the whole form, because in if I have my code, but it doesn't even go into this if. – user3171550 Jan 08 '14 at 03:09

1 Answers1

4

I'd say mysqli_real_escape_string errors out, as it has no database connection, which is its required first parameter (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 is empty So, either set up your database connection first, or escape later when you have it.

Moral of the story: enable proper error reporting and catch those errors early & quickly

Community
  • 1
  • 1
Wrikken
  • 69,272
  • 8
  • 97
  • 136