Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 奇怪的未定义变量错误_Php - Fatal编程技术网

Php 奇怪的未定义变量错误

Php 奇怪的未定义变量错误,php,Php,让我们直奔问题。我有以下表格: <?php if (isset($_POST['submit'])){ $username = $_POST['uname']; $email = $_POST['email']; $password = $_POST['pass']; $groups = $_POST['groups']; if($groups == "Main Admin"){ $level = 1; }else

让我们直奔问题。我有以下表格:

    <?php 
if (isset($_POST['submit'])){
    $username = $_POST['uname'];
    $email = $_POST['email'];
    $password = $_POST['pass'];
    $groups = $_POST['groups'];
    if($groups == "Main Admin"){
        $level = 1;
    }else if($groups == "Administrator"){
        $level = 2;
    }else if($groups == "Content Creator"){
        $level = 3;
    }else if($groups == "Social Media Manager"){
        $level = 4;
    }else{
        $level = 5;
    }
    if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
        $notice['email_validation'] = "The email that you have entered is not a valid one";
    }else{
        $registration = new Register();
        $notice = $registration->CheckUname($username,$email,$password,$groups‌​,$level);
    }   
}
?>
<div class="content-wrapper">
    <section class="content-header">
        <h1>
            Add New Admin
            <small>You can add new admin here</small>
        </h1>
        <ol class="breadcrumb">
            <li class="active">addnewadmin.php</li>
        </ol>
    </section>
    <section class="content">
        <div class="row">
            <div class="col-md-6">
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">Required Information</h3>
                    </div>
                    <?php 
                    if(isset($notice['email_validation'])) {
                        echo "
                            <div class='alert alert-danger'>
                                <strong>Hey!</strong> ".$notice['email_validation'].".
                            </div>
                        ";
                    }
                    if(isset($notice['username_exists'])) {
                        echo "
                            <div class='alert alert-danger'>
                                <strong>Hey!</strong> ".$notice['username_exists'].".
                            </div>
                        ";
                    }
                    if(isset($notice['email_exists'])) {
                        echo "
                            <div class='alert alert-danger'>
                                <strong>Hey!</strong> ".$notice['email_exists'].".
                            </div>
                        ";
                    }
                    if(isset($notice['success_message'])) {
                        echo "
                            <div class='alert alert-success'>
                                <strong>Hey!</strong> ".$notice['success_message'].".
                            </div>
                        ";
                    }
                    ?>
                    <form role="form" method="POST" action="">
                        <div class="box-body">
                            <div class="form-group">
                                <label>User name</label>
                                <input type="text" class="form-control" placeholder="Enter username" name="uname" required>
                            </div>
                            <div class="form-group">
                                <label for="exampleInputEmail1">Email address</label>
                                <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email" name="email" required>
                            </div>
                            <div class="form-group">
                                <label for="exampleInputPassword1">Temporary password</label>
                                <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Enter password" name="pass" required>
                            </div>
                            <div class="form-group">
                                <label>Group admin</label>
                                <select class="form-control" name="groups">
                                    <option value="Main Admin">Main Admin</option>
                                    <option value="Administrator">Administrator</option>
                                    <option value="Content Creator">Content Creator</option>
                                    <option value="Social Media Manager">Social Media Manager</option>
                                    <option value="Analyst">Analyst</option>
                                </select>
                            </div>
                        </div>
                        <div class="box-footer">
                            Visit <a href="https://zite.pouyavagefi.com/documentation/types.php">admin types</a> documentation to know the differences between each admin.
                        </div>
                        <div class="box-footer">
                            <button name="submit" type="submit" class="btn btn-primary">Submit</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </section>
</div>

绕一圈怎么样。您的代码如下

$registration = new Register();

$dataArray = array(
   'username'=>$username, 
   'email'=>$email, 
   'password'=>$password, 
   'groups‌'=>$groups‌, 
   'level'=>$level
);

$notice = $registration->CheckUname($dataArray);
并且像这样运作

public function CheckUname($dataArray)

这个$u POST['groups']真的有价值吗?在不确定数组索引是否存在的情况下访问它们,可能会引发有关未定义索引的警告。尝试更改此行$groups=$\u POST['groups'];to$groups=isset($\u POST['groups'])$_POST['groups']:空;执行变量转储($\u POST);另外,在分配后置值之前,请尝试初始化所有变量扫描您显示的原始错误尝试通过添加任何数字来更改变量名称,并检查问题是否仍然存在。例如:$groups和$groups我做了你所有的建议,问题就存在了
public function CheckUname($dataArray)