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

7
  • 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 while in development mode. Do note PHP is case sensitive as well, so $_post is incorrect as well Commented Jul 20, 2016 at 5:54
  • @DarkBee I am a bit confused. I just fixed the post issue, but can you elaborate a bit more on the $output problem? Commented Jul 20, 2016 at 5:57
  • @DarkBee He initialized $outputto NULLat 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 $outputis null. Commented Jul 20, 2016 at 5: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 Commented Jul 20, 2016 at 6:01
  • @DarkBee It appears none of these solutions worked. Please refer to the answer to see what didn't work. Commented Jul 20, 2016 at 6:01

3 Answers 3

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);
?>
Sign up to request clarification or add additional context in comments.

1 Comment

This did not fix it, it made it error even more. I am just going to scrap it and try using another method.
0

as pointed by DarkBee in comment you have many errors

if(isset($POST['submit']))  replace this with     if(isset($_POST['submit']))

1 Comment

I just tried this, now it is just echoing "Please fill in all fields", without giving me the chance to fill it in.
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!";
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.