0
<?php
    $output = NULL;
    $ip = $_SERVER['REMOTE_ADDR'];

    if (isset($POST['submit'])) {
        $username = $mysqli->real_escape_string($_post['username']);
        $password = $mysqli->real_escape_string($_post['password']);
        $rpassword = $mysqli->real_escape_string($_post['rpassword']);
        $email = $mysqli->real_escape_string($_post['email']);

        $query = $mysqli->query("SELECT * FROM users WHERE username = '$username'");
        if (empty($username) OR empty($password) OR empty($email) or empty($rpassword)) {
            $output = "Please fill in all fields!";
        } elseif ($query->num_rows != 0) {
            $output = "That username is already taken!";
        } elseif ($rpassword != $password) {
            $output = "Password does not match!";
        }
    }
?>

Later on in the script, I use this:

<?php
echo $output;
?>

It does not echo, and yes, I have added the mysqli query, but I removed it for the safety of the database. You can also see that it does not echo at the website: vobern.com

enricog
  • 4,226
  • 5
  • 35
  • 54
astral
  • 43
  • 5
  • 3
    You have a lot of typos in there. The problem is `$output` is never set as you test against `isset($POST['submit'])` which is always false, because thats a typo. Be sure to turn all [error_reporting](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php) while in development mode. Do note `PHP` is case sensitive as well, so `$_post` is incorrect as well – DarkBee Jul 20 '16 at 05:54
  • @DarkBee I am a bit confused. I just fixed the post issue, but can you elaborate a bit more on the $output problem? – astral Jul 20 '16 at 05:57
  • @DarkBee He initialized `$output`to `NULL`at the very top of the Script and he has no final `else` clause so this means that if all the 3 conditions in the `conditional logic` fail; the echo will always produce nothing since `$output`is `null`. – Poiz Jul 20 '16 at 05:59
  • 1
    @Poiz the first statement is: `if(isset($POST['submit'])){`, so those three you are talking about are never reached in the first place – DarkBee Jul 20 '16 at 06:01
  • @DarkBee It appears none of these solutions worked. Please refer to the answer to see what didn't work. – astral Jul 20 '16 at 06:01
  • @DarkBee Clear.... `$POST` not `$_POST`... Nice observation... Perfect... Thanks for the Pointer – Poiz Jul 20 '16 at 06:03
  • @Poiz I fixed that, and still doesn't work. Please check out my site to see what I mean – astral Jul 20 '16 at 06:05

3 Answers3

3

PHP is a case-sensitive Language. There is a difference between $_POST AND $_post. You may also want to take that into consideration. Now why don't you try doing it like below?

<?php
    $output         = NULL;
    $ip             = $_SERVER['REMOTE_ADDR'];

    if(isset($_POST['submit'])){
        // FOR THE VARIABLES BELOW, THERE IS A DIFFERENCE BETWEEN
        // $_POST AND $_post (AS YOU WROTE).... 
        $username   = htmlspecialchars(trim($_POST['username']));
        $password   = htmlspecialchars(trim($_POST['password']));
        $rpassword  = htmlspecialchars(trim($_POST['rpassword']));
        $email      = htmlspecialchars(trim($_POST['email']));

        $query      = $mysqli->query("SELECT * FROM users WHERE username = '$username'");

        if (empty($username) || empty($password) || empty($email) || empty($rpassword)){
            $output = "Please fill in all fields!";
        }elseif($query->num_rows != 0){
            $output = "That username is already taken!";
        }elseif ($rpassword != $password){
            $output = "Password does not match!";
        }
    }else{
        // IF THIS POINT IS REACHED, THEN EVERYTHING SHOULD BE OK
        $output     = "Login Data is Correct";
    }

    var_dump($output);
?>
Poiz
  • 7,611
  • 2
  • 15
  • 17
  • This did not fix it, it made it error even more. I am just going to scrap it and try using another method. – astral Jul 20 '16 at 06:19
0

as pointed by DarkBee in comment you have many errors

if(isset($POST['submit']))  replace this with     if(isset($_POST['submit']))
Passionate Coder
  • 7,154
  • 2
  • 19
  • 44
  • I just tried this, now it is just echoing "Please fill in all fields", without giving me the chance to fill it in. – astral Jul 20 '16 at 06:01
0

All $_post in your code should be $_POST in upper case. You add one more else to the last

    elseif ($rpassword != $password){
      $output = "Password does not match!";
    }else{
     $output = "Valid input!";
    }
Developer
  • 41
  • 4