php - 如果数据丢失则重定向到页面

标签 php mysql

好吧,我今天工作太久了,我被困在一些简单的事情上(我认为)

function commonData($uid)
{
    if ($uid)
    {
            $sql = "
                    SELECT a.user_id, a.email, a.username, a.displayname, a.level_id, a.photo_id
                    FROM engine4_users AS a
                    WHERE a.user_id = ".$uid;
    }

    $UserInfo = @mysql_fetch_assoc(mysql_query($sql));

    if ($UserInfo[user_id])
    {

            if ($UserInfo[photo_id] && $UserInfo[photo_id]!="NULL")
            {
                    $PPhoto = @mysql_fetch_assoc(mysql_query("SELECT a.* FROM engine4_storage_files AS a WHERE a.file_id = ".$UserInfo[photo_id]));
                    $photo = SITE.$PPhoto[storage_path];
            }
            else $photo = NO_PHOTO; 

    $queryMoreProfile = mysql_query("SELECT * FROM engine4_user_fields_values AS a WHERE a.item_id = ".$UserInfo[user_id]);

    while ($moreProfile = @mysql_fetch_assoc($queryMoreProfile))
    {

            //$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://www.fetishmen.net/members/edit/profile");
            //      exit;
            //}
}

我想做的是,如果 $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;
}

关于php - 如果数据丢失则重定向到页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13388534/

相关文章:

php - 调用未定义函数 mysql_query()

php - 检查值是否已存在于行而不是列单元格中

php pdo连接到mssql实例

javascript - 使用 highcharts api 和 mysql 显示饼图

mysql - 如何定义在数据库中存储值的特定范围?

php - 通过php将带有日期的csv导入到mysql

MySQL 大于 IN

php - 有效处理 'Big Data' 的技术(读取、写入、查询、聚合)

php - 如何在 PHP 中的类之间传递变量而不扩展

mysql - 如何更新二进制数的一位作为切换?