試圖在PHP和MySQLi中啓動一個函數,以便在用戶激活時返回TRUE(1)或者FALSE是用戶未激活(0)。MySQLi中的進程激活函數?
我測試了這些代碼,並沒有運氣,得到MySQLi錯誤。記住,我是MySQLi的新手。
function get_activated($mysqli, $userid) {
$row = $mysqli->query("SELECT * FROM users WHERE userid = '{$userid}' AND activated = '1'")->fetch_array();
if($row){
$activated = TRUE;
return $activated;
}
}
function get_activated($mysqli) {
$row = $mysqli->query("SELECT * FROM users WHERE userid = '{$userid}' AND activated = '1'")->fetch_array();
if($row){
$activated = TRUE;
return $activated;
}
}
function get_activated($mysqli, $userid) {
if(isset($_SESSION['userid'])) {
$userid = $_SESSION['userid'];
$row = $mysqli->query("SELECT * FROM users WHERE userid = '{$userid}' AND activated = '1'")->fetch_array();
if($row){
$activated = TRUE;
return $activated;
}
}
}
function get_activated($mysqli) {
if(isset($_SESSION['userid'])) {
$userid = $_SESSION['userid'];
$row = $mysqli->query("SELECT activated FROM users WHERE userid = '{$userid}'")->fetch_array();
return $row["activated"];
}
}
我打電話這樣的功能:
get_activated($userid);
echo $activated;
exit();
get_activated();
echo $row['activated'];
exit();
如果任何人都可以點我在正確的軌道在這裏我會很感激,謝謝!
錯誤例子:
缺少參數2 get_activated() 呼叫一個成員函數查詢()非對象上 只有變量應該通過引用 缺少參數1用於傳遞get_activated()
爲什麼你有這麼多被命名爲相同的函數? ('get_activated()')?另外,當你返回一個變量時,它被設置爲賦值給某個東西,而不是像你正在嘗試的那樣調用......它應該是這樣的:'$ activated = get_activated($ userid);' – Darren
顯示mysqli錯誤。 – ihsan
請將您遇到的錯誤置於問題中。 –