0

Parse error: syntax error, unexpected T_STRING这段代码在行给出解析错误$gender=$user['gender'];......这段代码有什么问题......需要帮助......谢谢

<?php
 require_once 'config/functions.php';
 session_start();
 $user=$_SESSION['google_data'];
 if(!empty($user)){
  $email = $user['email'];
  $fname = $user['given_name'];
  $lname = $user['family_name'];
  $gender=$user['gender'];
  $dob = $user['birthday'];
  $location = '';
  $picture = $user['picture'];
  $uid = $user['id'];
  $ousername = '';
  $link = $user['link'];
       $provider = 'google';
       $verified = $user['verified_email'];

      $gen=0;
      if($gender == 'male'){$gen=1;} else{$gen=0;}
      $new_dob = date( "Y-m-d H:i:s", strtotime($dob) );

      $userObj = new User();
      $userdata = $userObj->checkUser($email,$fname,$lname,$gen,$new_dob,$location,$picture,$uid,$ousername,$link,$provider,$new_verified); 
      if(!empty($userdata)){         
        $_SESSION['id'] = $userdata['user_id'];
        $_SESSION['oauth_id'] = $userdata['user_oauth_id'];
        $_SESSION['username'] = $userdata['user_oauth_username'];
        $_SESSION['picture'] = $userdata['picture'];            
        $_SESSION['link'] = $userdata['link'];
        $_SESSION['fname'] = $userdata['user_fname'];
        $_SESSION['lname'] = $userdata['user_lname'];
        $_SESSION['gender'] = $userdata['user_gender'];
        $_SESSION['email'] = $userdata['user_email'];
        $_SESSION['oauth_provider'] = $userdata['user_oauth_provider'];             
        $_SESSION['oauth_id'] = $uid;


     } else {
        # For testing purposes, if there was an error, let's kill the script
        die("There was an error.");

    }
  }
 ?>
4

3 回答 3

1

这条线可能是问题所在:

     }
     } 别的 {

于 2013-03-18T10:41:43.837 回答
1

您需要}从最后一个中删除,因为那是多余的。

所以最后一行将是。

} else {
      # For testing purposes, if there was an error, let's kill the script
      die("There was an error.");
 }

完整代码

<?php
    require_once 'config/functions.php';
    session_start();
    $user=$_SESSION['google_data'];

    if(!empty($user))
    {
        $email = $user['email'];
        $fname = $user['given_name'];
        $lname = $user['family_name'];
        $gender=$user['gender'];
        $dob = $user['birthday'];
        $location = '';
        $picture = $user['picture'];
        $uid = $user['id'];
        $ousername = '';
        $link = $user['link'];
        $provider = 'google';
        $verified = $user['verified_email'];

        $gen=0;
        if($gender == 'male'){$gen=1;} else{$gen=0;}

        $new_dob = date( "Y-m-d H:i:s", strtotime($dob) );

        $userObj = new User();
        $userdata = $userObj->checkUser($email,$fname,$lname,$gen,$new_dob,$location,$picture,$uid,$ousername,$link,$provider,$new_verified); 

        if(!empty($userdata))
        {
            $_SESSION['id'] = $userdata['user_id'];
            $_SESSION['oauth_id'] = $userdata['user_oauth_id'];
            $_SESSION['username'] = $userdata['user_oauth_username'];
            $_SESSION['picture'] = $userdata['picture'];            
            $_SESSION['link'] = $userdata['link'];
            $_SESSION['fname'] = $userdata['user_fname'];
            $_SESSION['lname'] = $userdata['user_lname'];
            $_SESSION['gender'] = $userdata['user_gender'];
            $_SESSION['email'] = $userdata['user_email'];
            $_SESSION['oauth_provider'] = $userdata['user_oauth_provider'];             
            $_SESSION['oauth_id'] = $uid;

        }
    }
    else
    {
        die("There was an error.");
    }
?>
于 2013-03-18T10:55:32.000 回答
0

请像这样使用

$gender = isset( $user['gender'] ) ? $user['gender'] : '' ;
于 2013-03-18T10:52:50.117 回答