我正在使用PHP PDO开发用户帐户系统。基本上,在profile.php?username={username}
页上,我这样做:
if(isset($_GET['username'])){
$query = $db->query("SELECT * FROM `users` WHERE 'uname' = '" . $_SESSION['uname'] . "'");
while($u = $query->fetch()){
echo "
<div class='row' style='text-align:center;margin-left:30%;'>
<div class='col-xs-12 col-sm-6 col-md-6'>
<div class='well well-sm'>
<div class='row'>
<div class='col-sm-6 col-md-8'>
<h4>" . $_SESSION['uname'] . "</h4>
<i class='glyphicon glyphicon-envelope'></i>" . $u["email"] . "
</div>
</div>
</div>
</div>
</div>
";
}
}
但是现在的问题是它什么也没显示。.我的意思是没有错误,也没有输出!而且,当我看到页面源代码时,没有出现任何错误!
那么这里是什么问题?请帮我解决这个问题,因为这确实让我感到困惑。
这里是pdo_conx.php
:
<?php
$servername = "localhost";
$username = "root";
$password = "";
try {
$db = new PDO("mysql:host=$servername;dbname=myshop", $username, $password);
}
catch(PDOException $e)
{
die("Connection failed: " . $e->getMessage());
}
?>
答案 0 :(得分:1)
$query = $db->query("SELECT * FROM `users` WHERE 'uname' = '" . $_SESSION['uname'] . "'");
必须更改为:
$query = $db->query("SELECT * FROM `users` WHERE uname = '" . $_SESSION['uname'] . "'");