我正试图从我的本地数据库中获取一个特定的值,但似乎它确实起作用,这是我的代码:
$acceptance = " SELECT acceptance_status FROM teams_0517 WHERE team_id=$team_id";
$acceptancex = mysql_query($acceptance);
mysql_close($connection);
if($acceptancex == 0)
{
ob_clean();
header('Location: index.php');
ob_flush();
}
else
{
ob_clean();
header('Location: signup.php');
ob_flush();
}
当我运行代码时,php将跳过if条件并继续执行其他语句,因此似乎$acceptance
没有值..有什么帮助吗?
答案 0 :(得分:1)
执行查询后需要获取结果。 见how to fetch
尝试这样:
$acceptance = " SELECT acceptance_status FROM teams_0517 WHERE team_id=$team_id limit 1";
$result = mysql_query($acceptance);
$acceptancex = mysql_fetch_object($result); // fetch object
if($acceptancex->acceptance_status == 0)
{
ob_clean();
mysql_close($connection);
header('Location: index.php');
ob_flush();
}
else
{
ob_clean();
mysql_close($connection);
header('Location: signup.php');
ob_flush();
}
答案 1 :(得分:1)
试试这个: -
$acceptance = " SELECT acceptance_status FROM teams_0517 WHERE team_id=$team_id limit 1";
$result = mysql_query($acceptance);
$acceptancex = mysql_fetch_object($result); // fetch object
if($acceptancex->acceptance_status == 0)
{
$redirect = "index.php";
}
else
{
$redirect = "signup.php";
}
mysql_close($connection);
ob_clean();
header('Location: '.$redirect);
ob_flush();