我收到了上述错误。我在conn.php中有数据库连接,我在fn.php中包含了这个连接。但是,在特定行上它会给出错误
注意:未定义的变量:在第16行的fn.php中重新存在
第16行是:
$a = mysqli_query($rezistent, "SELECT is_verified FROM users WHERE veri_key = '$key'") or die(mysqli_error());
这是我的conn.php
<?php
$user = "mmoin";
$pass = "pass";
$host = "localhost";
$dbname = "rezistent";
$rezistent = mysqli_connect($host, $user, $pass, $dbname) or die("cannot connect with database");
?>
这是fn.php
<?php
include "conn.php";
function hashit($v){
$hash = md5($v);
$hash .= rand(11,99);
return $hash;
}
function user_verification($k){
$account_type = substr($k, 0, 1);
$key = substr($k, 1);
$msg_to_display = "";
if($account_type == "h" || $account_type == "t"){
$a = mysqli_query($rezistent, "SELECT is_verified FROM users WHERE veri_key = '$key'") or die(mysqli_error());
$rows = mysqli_num_rows($a);
if($rows > 0){
mysqli_query($rezistent, "UPDATE users SET is_verified = '1' WHERE veri_key='$key'");
$msg_to_display = "User successfully verified. Please use the login link to login with your credentials.";
}
}
else{
$msg_to_display = "There seems to be a problem with the verification key. Please try again from the link provided in the email.";
}
return $msg_to_display;
}
?>
可能是什么问题?我甚至尝试在函数之前立即连接数据库,但它仍然会给出相同的通知消息。
答案 0 :(得分:1)
答案 1 :(得分:0)
这是因为$rezistent
未在函数user_verification
的范围内定义,这并不意味着数据库连接被拒绝。
解决方案:
将$rezistent
作为第二个参数发送给函数。
function user_verification($k, $rezistent){