1

你好,如果我想不出“else if”的话,我对 else 没什么问题,如果

$photo = 'http://www.localhost/uploads/'.$usersInfo['image_id'].'.jpg';
$photoModeImage = 'http://www.localhost/uploads/thumbs/'.$usersInfo['image_id'].'.jpg';

出错了,否则如果应该选择照片

<?php
require_once '../../../common/server/php/settings.php';



//Connect to users database
$db = mysql_connect('localhost','root','123456') or die(mysql_error());
mysql_select_db('registracija',$db) or die(mysql_error());

//Init request parameters
$userName = (isset($_REQUEST["user_name"])) ? urldecode($_REQUEST["user_name"]) : "";
$password = (isset($_REQUEST["password"])) ? urldecode($_REQUEST["password"]) : "";
$uid = (isset($_REQUEST["uid"])) ? urldecode($_REQUEST["uid"]) : "";
$pwdmd5 = md5($password);

//Check if user filled login and password in the login screen (Chat authorization)
if($userName != "" && $password != "")
{
  $sql = "SELECT * FROM users WHERE username='".$userName."' AND password='".$pwdmd5."'";
}
//session/cookie base authorization (Auto login)
else if ($_SESSION['user_id']!="")
{
  $sql = "SELECT * FROM users WHERE Profile_id='".$_SESSION["user_id"]."'";
}
// Non session/cookie based autologin authorization
else if ($uid!="")
{
  $sql = "SELECT * FROM users WHERE id='".$_GET['uid']."'";
}
else
{
  echo '<auth error="AUTH_ERROR" />';
  exit;
}

//Select user data
$result = mysql_query($sql,$db);

if(mysql_num_rows($result)==1)
{
  //User found. get user info
  $usersInfo = mysql_fetch_array($result);
  if($userInfo['image_id'] ==''){
    $photo = FLASHCOMS_HTTP_ROOT.'common/images/User1_120.png';
    $photoModeImage = FLASHCOMS_HTTP_ROOT.'common/images/User1_40.png';  
  }
  else{
    $photo = 'http://127.0.0.1:8082/uploads/'.$usersInfo['image_id'].'.jpg';
    $photoModeImage = 'http://127.0.0.1:8082/uploads/thumbs/'.$usersInfo['image_id'].'.jpg';
  }
  $answer = '<auth>';
  $answer .= '<userName><![CDATA['.$userName.']]></userName>';
  $answer .= '<gender>male</gender>';
  $answer .= '<age>'.$userInfo['age'].'</age>';
  $answer .= '<level>regular</level>';
  $answer .= '<photo><![CDATA['.$photo.']]></photo>';
  $answer .= '<photoModeImage><![CDATA['.$photoModeImage.']]></photoModeImage>';
  $answer .= '</auth>';
  echo $answer;
  exit;
}
else 
{
  //User not found OR authorization failed
  echo '<auth error="AUTH_ERROR" />';
  exit;
}

?>

我需要让它工作的是

else if ($photo['$image_id']!='')
    {

    $photo = FLASHCOMS_HTTP_ROOT.'common/images/no_photo.png';
    $photoModeImage = FLASHCOMS_HTTP_ROOT.'common/images/no_photo.png';

但图像没有显示。

-- ----------------------------
-- Table structure for `users`
-- ----------------------------
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
  `id_user` int(11) NOT NULL auto_increment,
  `name` varchar(128) NOT NULL,
  `email` varchar(64) NOT NULL,
  `age` varchar(16) NOT NULL,
  `username` varchar(16) NOT NULL,
  `password` varchar(32) NOT NULL,
  `confirmcode` varchar(32) default NULL,
  `gender` varchar(32) NOT NULL,
  `country` varchar(20) NOT NULL,
  `city` varchar(20) NOT NULL,
  `about_me` varchar(200) NOT NULL,
  `image_id` varchar(10000) NOT NULL,
  PRIMARY KEY  (`id_user`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

-- ----------------------------
-- Records of users
-- ----------------------------
INSERT INTO `users` VALUES ('1', '', 'localhost@myemail.com', '', 'Mentro', '5f4dcc3b5aa765d61d8327deb882cf99', 'y', '', '', '', '', '1');
4

1 回答 1

0

我认为您正在尝试no_photo.png为没有用户图片的用户进行设置。如果我是对的,那么请执行以下操作:

1)确保FLASHCOMS_HTTP_ROOT.'common/images/no_photo.png'存在。

2)将其更改为:

if(mysql_num_rows($result)==1)
{
  //User found. get user info
  $usersInfo = mysql_fetch_array($result);
  if($userInfo['image_id'] ==''){
    $photo = FLASHCOMS_HTTP_ROOT.'common/images/User1_120.png';
    $photoModeImage = FLASHCOMS_HTTP_ROOT.'common/images/User1_40.png';    
  }
  else{
    $photo = 'http://127.0.0.1:8082/uploads/'.$usersInfo['image_id'].'.jpg';
    $photoModeImage = 'http://127.0.0.1:8082/uploads/thumbs/'.$usersInfo['image_id'].'.jpg';
  }
  $answer = '<auth>';
  $answer .= '<userName><![CDATA['.$userName.']]></userName>';
  $answer .= '<gender>male</gender>';
  $answer .= '<age>'.$userInfo['age'].'</age>';
  $answer .= '<level>regular</level>';
  $answer .= '<photo><![CDATA['.$photo.']]></photo>';
  $answer .= '<photoModeImage><![CDATA['.$photoModeImage.']]></photoModeImage>';
  $answer .= '</auth>';
  echo $answer;
  exit;
}
else 
{
  //User not found OR authorization failed
  echo '<auth error="AUTH_ERROR" />';
  exit;
}

?>
于 2013-01-30T10:48:41.287 回答