我遇到一个问题,我的页面会抛出一个"没有选择数据库"我登录时出错但在我没有登录时工作正常。这是我的代码:
$cat = $_GET['cat'];
// IF NOT LOGGED ON -- ONLY ALLOW PUBLIC CATS TO BE SELECTED!!
if ($_SESSION['logged'] != 'on') {
$sql = sprintf("SELECT * FROM diningcategories WHERE publish='1' AND catName='%s'",
mysqli_real_escape_string($spositas, $cat));
}
// IF LOGGED ON ALLOW UNPUBLISHED CATEGORIES TO BE SELECTED
else {
$sql = sprintf("SELECT * FROM diningcategories WHERE catName='%s'",
mysqli_real_escape_string($spositas, $cat));
}
mysqli_select_db($spositas, 'spositas_db');
$selectCat = mysqli_query($spositas, $sql) or die(mysqli_error($spositas));
$selectedCat = mysqli_fetch_assoc($selectCat);
// IF NOT LOGGED ON SELECT PUBLIC MENU ITEMS BASED ON CATEGORY
if ($_SESSION['logged'] != 'on') {
$sql = sprintf("SELECT * FROM diningmenu WHERE displayOnMenu='1' AND Category='%s'",
mysqli_real_escape_string($spositas, $cat));
}
// IF LOGGED ON ALLOW ALL MENU ITMES TO BE DISPLAYED
else {
$sql = sprintf("SELECT * FROM diningmenu WHERE Category='%s'",
mysqli_real_escape_string($spositas, $cat));
}
mysqli_select_db($spositas, 'spositas_db');
$selectMenuItems = mysqli_query($spositas, $sql) or die(mysqli_error($spositas));
$menuItems = mysqli_fetch_assoc($selectMenuItems);
我搜索并浏览了许多类似于我的问题,但我很难解决我的问题。