Php 如果数据丢失,则重定向到页面
好吧,我今天工作的时间太长了,我被一些简单的事情困住了(我想)Php 如果数据丢失,则重定向到页面,php,mysql,Php,Mysql,好吧,我今天工作的时间太长了,我被一些简单的事情困住了(我想) 我想说的是,如果$location没有任何值(数据库完全丢失),则重定向到页面。我做错了什么?数组的索引$moreProfile和$locationsql需要是变量或字符串 if ($moreProfile['field_id']==24) //or $field_id { $locationNumber = $moreProfile['value']; //or $value $locationsql = @mys
我想说的是,如果
$location
没有任何值(数据库完全丢失),则重定向到页面。我做错了什么?数组的索引$moreProfile
和$locationsql
需要是变量或字符串
if ($moreProfile['field_id']==24) //or $field_id
{
$locationNumber = $moreProfile['value']; //or $value
$locationsql = @mysql_fetch_assoc(mysql_query("SELECT a.* FROM engine4_user_fields_options AS a WHERE a.option_id = ".$locationNumber));
$location = $locationsql['label']; //or $label
}
if(empty($location))
{
header("Location: http://website.com");
exit;
}
编辑:根据OP的评论
if ($moreProfile['field_id'] == 24 )
{
$locationNumber = $moreProfile['value']; //or $value
$locationsql = @mysql_fetch_assoc(mysql_query("SELECT a.* FROM engine4_user_fields_options AS a WHERE a.option_id = ".$locationNumber));
$location = $locationsql['label']; //or $label
} else if(empty($moreProfile['field_id'])) {
header("Location: http://website.com");
exit;
}
您应该停止使用@,并进行适当的检查,确保mysql\u result和mysql\u fetch\u assoc正在返回某些内容。试试这个,看看它是否为您重定向:
$location = '';
if ($moreProfile['field_id']==24)
{
$locationNumber = $moreProfile['value'];
$locationsql = @mysql_fetch_assoc(mysql_query("SELECT a.* FROM engine4_user_fields_options AS a WHERE a.option_id = ".$locationNumber));
if (isset($locationsql['label']) && !empty($locationsql['label'])) {
$location = $locationsql['label'];
}
}
if(empty($location))
{
header("Location: http://website.com");
exit;
}
这是我应该澄清以上内容的地方$queryMoreProfile=mysql_query(“从engine4_用户_字段中选择*作为WHERE a.item_id=“.UserInfo[user_id]);虽然($moreProfile=@mysql\u fetch\u assoc($queryMoreProfile)),但如果我看起来像个傻瓜,我很抱歉。。。我只是感到疲倦和困惑,无法理解这一点,也无法将其从我的脑海中抹去。这是表
engine4\u user\u fields\u values
中的一列。是的。。。因此,基本上,在这种情况下,它要么将24作为“字段id”,要么将找不到任何数据。为了澄清,它将首先提取用户id的所有数据。。。然后,如果用户ID的字段ID为24,则会有一个相应的“值”,但如果该字段ID为24,则我需要它将其重定向到一个页面以修复其配置文件no sorry did work。。。不幸的是,我认为这是一个背景问题。。。你真的应该看看整个文件,但我知道这里的人不喜欢。。。我想我会再花10分钟看一看,然后留到晚上。。。我会在早上查看更多的建议,“没有工作”在这里对我没有帮助。您得到的错误是什么?因此,基本上我在脚本上得到的错误是身份验证失败。此脚本是一系列身份验证类型的通用.handler。文件的这一部分用于提取聊天网站的用户配置文件信息。您看到的是where子句下的函数。它是wierd,因为如果我删除顶部的$location行并删除所有if(空..声明它可以工作,如果用户设置了他们的位置,它就会显示出来..如果他们没有国家/地区设置,我尝试将他们转发到编辑配置文件页面。这更有意义吗?不确定确切的问题是什么。可能是您的代码从未到达if($moreProfile['field_id']==24)lineit确实到达了那里,因为数据已经填充好了,所以我发布了函数的全部代码…是的,我删掉了一些不适用的if语句…我希望这能有所帮助
$location = '';
if ($moreProfile['field_id']==24)
{
$locationNumber = $moreProfile['value'];
$locationsql = @mysql_fetch_assoc(mysql_query("SELECT a.* FROM engine4_user_fields_options AS a WHERE a.option_id = ".$locationNumber));
if (isset($locationsql['label']) && !empty($locationsql['label'])) {
$location = $locationsql['label'];
}
}
if(empty($location))
{
header("Location: http://website.com");
exit;
}