我想要做以下但失敗。
$user_id = $_REQUEST['user_id'];
if (/* nothing to be requested*/) {
echo "<button>Log In</button><button>Sign Up</button>";
} else {
/* logged in, check if the user is an admin or not */
if (/* he is admin */) {
echo "<button>Admin</button><button>Logout</button>";
} else {
/* then he is just a normal user */
echo "<button>Logout</button>";
}
}
原始代碼:
$user_id = $_REQUEST['user_id'];
if (!$user_id) {
echo "<button>Log In</button><button>Sign Up</button>"
} else {
$check_sql = "SELECT admin from users where user_id = {'$user_id'}";
$result = mysqli_query($con, $check_sql);
$rows = mysqli_fetch_array($con, $result);
if ($rows['admin'] == 1) {
echo "<button>Admin</button><button>Log Out</button>";
} else {
echo "<button>Log Out</button>";
}
}
當有是$ _REQUEST爲user_id,代碼工作正常。但是當沒有什麼是$ _REQUEST時就會失敗。你能幫忙嗎?
非常感謝!
把這個:如果(空($ user_ID的)) – bfahmi
的使用,如果(空($ user_ID的)){} – JYoThI
利用這一點,如果(isset($ user_ID的)!) – rajeev