我想要做的是在提交此表單時。它檢查數據庫中匹配用戶名的firstname字段是否爲空。如果爲空,那麼用戶應該被重定向到某個地方,如果它不是空的,用戶將被重定向到其他地方。以下是我的代碼,在其中不幸的是不工作。檢查數據庫中的某個字段是否爲空然後重定向
<?php
include_once 'db_connect.php';
include_once 'functions.php';
$user = $_SESSION['username'];
sec_session_start(); // Our custom secure way of starting a PHP session.
if (isset($_POST['email'], $_POST['p'])) {
$email = $_POST['email'];
$password = $_POST['p']; // The hashed password.
if (login($email, $password, $mysqli) == true) {
$server = "localhost";
$user = "";
$pass = "";
$db = "";
$mysqli = new Mysqli($server, $user, $pass, $db) or mysqli_error($mysqli);
$firstname = $mysqli->query("SELECT firstname FROM members WHERE username = '$user'")->fetch_object()->firstname;
if(empty($firstname)) {
// Login success
header('Location: ../updateinfo.php');
} else {
header('Location: ../services.php');
}
} else {
// Login failed
header('Location: ../index.php?error=1');
}
} else {
// The correct POST variables were not sent to this page.
echo 'Invalid Request';
}
任何想法我錯了?您執行的查詢權之前
$user = "";
:因爲你設置
是什麼問題?它是否將一個非空值視爲空,反之亦然? – Barmar
沒有它根本不工作。它在任何情況下都會保持重定向到updateinfo.php。 –
@Barmar當我試圖做!空($ firstname)它重定向到services.php –