PHP错误警告:mysqli_query()期望参数1为mysqli,null为null

时间:2017-01-16 21:13:19

标签: php mysqli parameters

所以...我收到这个错误“警告:mysqli_query()期望参数1是mysqli,在”但是只有在尝试从另一个页面访问函数时才会给出null。如果我将变量放在同一个PHP文件中并在同一个文件中调用该函数,那么它就可以工作了。

这是调用函数“mylogin()”

的文件的PHP
<?php

require_once "mysqlconn.php";
require_once "login.php";

$key = md5('mykey'); 
$salt = md5('mysalt');

function encrypt($string, $key){

    $string = rtrim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $string, MCRYPT_MODE_ECB))); 
    return $string; 

    }

function decrypt($string, $key){

    $string = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, base64_decode($string), MCRYPT_MODE_ECB)); 
    return $string; 

}

function hashword($string, $salt){

    $string = crypt($string, '$1%' . $salt . '$');
    return $string;

}; 

if(isset($_POST['submit'])){

    $firstname = encrypt($_POST['firstname'],$key);
    $lastname = encrypt($_POST['lastname'],$key); 
    $username = encrypt($_POST['username'],$key); 
    $password = hashword($_POST['password'],$salt);
    $passwordconf = hashword($_POST['passconf'],$salt); 
    $email = encrypt($_POST['email'],$key);

    if(username == NULL){

        $msg = 'Please Enter a UserName'; 
        echo $msg;

        }else{

        if($password == NULL){

            $msg = 'Please Enter a Password';
            echo $msg;

            }else{

            if($passwordconf <> $password){

                $msg = 'Please Ensure Your Password Matches';
                echo $msg;

                }else{

                if($email == NULL){

                    $msg = 'Please Enter a valid Email address';
                    echo $msg;

                    } else{

                    $sql = "insert into Users(uname,fname, lname, pw, eml) Values ('".$username."','".$firstname."','".$lastname."','".$password."','".$email."')";
                    mysqli_query($link,$sql);    
                    $res = mylogin($username,$password);
                    echo $res; 

                    }   


                }    

            }

        }

    }

?>

这引用了login.php文件

  <?php


 //$username = 'username';
 //$password = 'password'; 
 //$rest = mylogin($username,$password);
 //echo $rest;
function mylogin($username,$password){

    require_once "mysqlconn.php";

    $sqllogin = "select ID from Users where UserName = '" .$username. "' and Password = '" .$password. "'"; 
    $res = mysqli_query($link,$sqllogin) or die(mysqli_error($link));

    while ($row = $res->fetch_assoc()){

        $ID = $row['ID']; 

        }

    if ($ID == NULL){

        $ID = "Username or Password Incorrect";

        }

    return $ID;

    }

?>

建议?

0 个答案:

没有答案