简体   繁体   English

PHP-变量不回显

[英]PHP - Variable not echoing

<?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. 它不回显,是的,我已经添加了mysqli查询,但是为了数据库的安全我删除了它。 You can also see that it does not echo at the website: vobern.com 您也可以在以下网站上看到它没有回声:vobern.com

PHP is a case-sensitive Language. PHP是区分大小写的语言。 There is a difference between $_POST AND $_post . $_POST$_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);
?>

正如DarkBee在评论中指出的DarkBee ,您有很多错误

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

All $_post in your code should be $_POST in upper case. 您代码中的所有$ _post均应为$ _POST大写。 You add one more else to the last 您再添加一个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM