drryyiuib43562604 2014-06-25 19:46
浏览 17
已采纳

无法在URL中获取用户名

So I'm trying to make public profiles. So i'm getting the result from the database and shooting it back. Here's my code

$username = $con->prepare("SELECT username FROM users WHERE email=:email");
$username->bindValue(':email', $email, PDO::PARAM_STR);
$username->execute();
$userurl = $_GET['username'];

For some reason I'm not getting anything back. No errors either. Any help would be great. So basically what I want to do is get example.com/profile?username=joe

  • 写回答

1条回答 默认 最新

  • duandunzhuo3234 2014-06-25 19:52
    关注
    $stmt = $con->prepare("SELECT username FROM users WHERE email=:email");
    $stmt->bindValue(':email', $email, PDO::PARAM_STR);
    $stmt->execute();
    
    $row = $stmt->fetch();
    $username = $row['username'];
    
    
    $userurl = "example.com/profile?username=$username";
    header("Location: $userurl") ;
    

    You executed the query but never fetched the data, $_GET doesn't do what you think, it is meant to get a query string value.

    As the @Rangad and @David pointed out in the comment below, you should generate the query string using http_build_query:

    ...
    $stmt->execute(); 
    $row = $stmt->fetch();
    header('Location: example.com/profile?'.http_build_query($row)) ;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料