2012-11-14 26 views
0

行,所以我今天已經工作的時間太長了,我停留在一些簡單的(我認爲)重定向到頁面,如果數據丟失

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有沒有值(完全丟失數據庫)重定向到頁面。我在這裏做錯了什麼?

+0

行,所以我張貼整個代碼的功能......是我剪了一些,如果不適用的陳述......我希望幫助 – BossRyan

回答

2

陣列$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; 
} 

編輯:每個操作的評論作爲,

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; 
} 
+0

這是在哪裏我應該澄清以上內容... $ queryMoreProfile = mysql_query(「SELECT * FROM engine4_user_fields_values AS a WHERE a.item_id =」。$ UserInfo [user_id]); 而($ moreProfile = @mysql_fetch_assoc($ queryMoreProfile)) – BossRyan

+0

我很抱歉,如果我看起來像一個小白......我只是累了,困惑和無法想出解決辦法,並把它弄出來我的頭 – BossRyan

+0

的是'FIELD_ID '表'engine4_user_fields_values'中的一列? –

0

應停止使用@並且適當地檢查mysql_result和mysql_fetch_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; 
} 
+0

不知道它打破了整個腳本...對不起@paul – BossRyan

+0

更正了一個錯字,現在就試試吧。 –

+0

沒有抱歉沒有工作......不幸的是,我認爲這是一個上下文的東西...你應該看到整個文件,但我知道這裏的人不喜歡這個......我想我會再花10分鐘看看在它然後離開它的晚上...我會在早上檢查更多的建議 – BossRyan

相關問題