我收到提到的錯誤。我有conn.php中的數據庫連接,其中包括在fn.php中。然而,在一個特定的行它給錯誤注意:未定義變量:rezistent。凡rezistent指數據庫
注意:未定義的變量:rezistent在fn.php第16行
第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;
}
?>
可能是什麼問題?我曾嘗試在函數之前立即連接數據庫,但它仍然提供相同的通知消息。
在你的函數中包含conn.php user_verification() – Horen
'mysqli_query()'期望查詢是第一個參數,資源是第二個參數,所以你的參數是相反的。但我不認爲這是問題。你有沒有嘗試'echo' $ rezistent'來查看它是否返回資源句柄? –
爲了闡明@ Horen的評論,值'$ rezistent'不在你的函數範圍內。你可能需要按照他的建議包含它,將它作爲參數傳遞給函數,或者將其作爲全局函數加入。 –